Extensions > Templates

Detecting frontpage

(1/1)

jesusto:
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

webgift:
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!'; }

jesusto:
Great Webgift!!

I will check as soon as possible.

Thanks a lot for your great work helping in this forum.

jesusto:
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

datahell:
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 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.

Navigation

[0] Message Index

Go to full version