Elxis CMS Forum
Extensions => Templates => Topic started by: jesusto on January 07, 2016, 01:25:39
-
Hello,
I´m developing my own template.
How can I detect if we are in frontapage or the main page of the site to serve different content or modules?
I need the code to include in my template.
Thanks a lot for your support.
Regards
-
The main goal here is to check if we are in the same URL as the parameter named 'Default Route'
from Global settings of Elxis. So:
if (eFactory::getURI()->getUriString() == eFactory::getElxis()->getConfig('DEFAULT_ROUTE')) {
echo 'Frontpage found!';
}
I usually create an array with all the possible front pages:
$fronts = array('content:/', 'content', 'reservations', 'reservations:/', 'reservations:', '', '/', eFactory::getElxis()->getConfig('DEFAULT_ROUTE'));
And i finally check if the current page's URL consist the same with one of array's values:
if (in_array(eFactory::getURI()->getUriString(), $fronts)) { echo 'Frontpage found!'; }
-
Great Webgift!!
I will check as soon as possible.
Thanks a lot for your great work helping in this forum.
-
It works great Webgift,
Perhaps you can help when this:
I want to "stop the template" under certain circumstances so I use die() or exit() but I get this text in the screen [:head:]
How can I avoid this text to appear?
Thanks a lot
-
Bad practice... The template is not an application, it just styles the html elxis generates. Elxis, or a component, decides if execution needs to be stopped, not the template.
Why you see [:head:]
Elxis uses output buffering, meaning that stores everything in memory before displaying it to your screen. When you design a template you place in it code blocks to load the component, the modules, etc. When Elxis parse your template the Elxis Document (https://www.elxis.net/docs/developers/libraries/elxisdocument.html) library replaces your code blocks with special marks as [:head:] It executes the code of these blocks and puts the output into memory. When all blocks have been executed it replaces these marks with the actual html from the memory generating a full html page. Finally it shows you result html page.
You see [:head:] because you stopped Elxis Document reading the template before it is finished.
Other such special marks: [:pathway:], [:replmark1:], [:replmark2:], ..., [:toolbar:], [:component:]
For those what to experiment with Elxis output buffering
Open this file: includes/libraries/elxis/document.class.php
Go to line 1198
private function dispatch($compress=0) {
Add below:
$this->sendHeaders();
echo $this->buffer['template'];
return;
Go see your site now. It is your template's html without the Elxis generated html blocks.