Welcome,
Guest
.
Please
login
or
register
.
Did you miss your
activation email
?
News:
Convert
Wordpress to Elxis
with
Elxis importer
!
Home
Help
Login
Register
Elxis CMS Forum
»
Extensions
»
Templates
(Moderators:
Coursar
,
ks-net
) »
Detecting frontpage
« previous
next »
Print
Pages: [
1
]
Author
Topic: Detecting frontpage (Read 7917 times)
jesusto
Jr. Member
Posts: 68
Detecting frontpage
«
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
Logged
webgift
Elxis Team
Hero Member
Posts: 4193
Re: Detecting frontpage
«
Reply #1 on:
January 09, 2016, 09:22:16 »
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!'; }
Logged
Elxis Team •
Custom web design [EN]
-
[EL]
•
.GR Registrar
jesusto
Jr. Member
Posts: 68
Re: Detecting frontpage
«
Reply #2 on:
January 09, 2016, 13:43:26 »
Great Webgift!!
I will check as soon as possible.
Thanks a lot for your great work helping in this forum.
Logged
jesusto
Jr. Member
Posts: 68
Re: Detecting frontpage
«
Reply #3 on:
January 09, 2016, 14:22:58 »
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
Logged
datahell
Elxis Team
Hero Member
Posts: 10356
Re: Detecting frontpage
«
Reply #4 on:
January 09, 2016, 18:49:32 »
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.
«
Last Edit: January 09, 2016, 19:00:11 by datahell
»
Logged
Elxis Team
|
Is Open Source
|
IOS Rentals | IOS AERO
Print
Pages: [
1
]
« previous
next »
Elxis CMS Forum
»
Extensions
»
Templates
(Moderators:
Coursar
,
ks-net
) »
Detecting frontpage