Elxis CMS Forum
Support => Elxis 4.x/5.x DEV => Topic started by: xmanhattan on December 11, 2012, 10:51:25
-
Hello all,
In 2009.x multiple templates were assigned separately.
In Nautilus, say I am using Aiolos, do I have to make variations of it to have a different style for different pages? e.g. front page, eblog, content pages.
Also, how would a different template style be applied to the different content?
-
In Elxis 4.x only one template can be used.
To apply different style on a page the template must support that. So this functionality in Elxis 4.x has been passed to the template it self.
For instance on the default Delta template you can hide columns on specific pages. At elxis.net (https://www.elxis.net) for example the template displays no columns on component EDC pages (the left column shown is from the component, not the template) but it does show a right column in rest pages, like the search page (https://www.elxis.net/search/).
-
That's fine but I am still trying to figure out the strategy of how this can be done.
You mention At elxis.net for example the template displays no columns on component EDC pages (the left column shown is from the component, not the template) but it does show a right column in rest pages, like the search page.
but what I want to do is to justify the moving of older elxis sites to nautilus, and that means being able to provide different styles as well. As you know, clients want something shiny bright when asking for more money and the majority do not know or understand or care what the technology is working in the background. The popularity of some other systems is sadly based on looks and not the ingenuity such as that which Elxis offers combining the parameterization and simplicity for users in one package.
Are you or webgift writing additional information regarding templating at the docs site?
-
We will definitely write more articles in elxis.net/docs/ (https://www.elxis.net/docs/). I personally wrote 3 articles yesterday for Elxis database (https://www.elxis.net/docs/developers/database/).
You can do whatever you like in an Elxis 4.x template, the system is very powerful. The real question is can YOU do it? Some tasks require skills. Many important Elxis libraries are already documented and the developer can also open the rest and read them. If you understand elxisURI (https://www.elxis.net/docs/developers/libraries/elxisuri.html) you can play whatever games you want with the user request.
As we route components we can also route a template for different style per page.
An example/idea by using URI segments.
$segments = eFactory::getURI()->getSegments();
$c = count($segments);
$cssfile = 'style1.css';
if ($c > 0) {
switch (segments[0]) {
case 'category1': $cssfile = 'style2.css'; break;
case 'category2': 'category4': $cssfile = 'style3.css'; break;
case 'user': 'mygallery.html': $cssfile = 'style4.css'; break;
default: break;
}
}
$link = eFactory::getElxis()->secureBase().'/templates/mytemplate/css/'.$cssfile;
eFactory::getDocument()->addStyleLink($link);
An example/idea by using requested component and different layout per component.
$component = eFactory::getURI()->getComponent();
$layout = '2columns.php';
switch ($component) {
case 'user': $layout = '3columns.php'; break;
case 'search': 'something': $layout = 'nocolumns.php'; break;
default: break;
}
include(ELXIS_PATH.'/templates/mytemplate/'.$layout);
You can not only change the css file depending on the user request, but also the whole template's html layout including, module positions, and everything else a template has.
So, the real question is: Elxis can do it, you?
-
Datahell,
Personally, I admire your work. At first I believed that Nautilus was going to be improved, and it is, while following something similar along the previous versions.
From what I am seeing, Nautilus has gone to a higher level that is more along the lines of the enterprise usage. While this maybe good overall, it will most likely mean that for smaller organizations it may become more frustrating for an admin to make changes as easily as in 2009.x.
I think that we will see what happens and how the current users will react, hopefully positive. It is like giving someone a Lamborghini when they only need a Yugo.
As for the coding, yes I do understand how the coding that you have shown works. I do not know where e.g. the array segments[0]
comes from but I assume that as you have explained a variety of variables for databases, that I will learn more when the template documentation is available.
This new method opens many new ideas and possibilities for professional websites.
The 2 examples are very helpful; I look forward to seeing more information so that I can plan the reorganization and redesign of my website and others.
The only problem is that it will requie a new training or learning period.
I believe that Elxis is still #1.
Thank you
-
Let's say we have this URL: http://www.example.com/el/asia/japan/tokyo.html?x=1
Remove any existing query string (?x=1) from the end, remove site base url ( http://www.example.com/ ), any existing language identifier (el/) and you will have this:
asia/japan/tokyo.html
This is the URI string.
If we split this string by using the slash (/) character as delimiter you will get the URI segments, which is an array:
$segments = array('asia', 'japan', 'tokyo.html');
The index of the first element is 0 (asia), of the second is 1 (japan) and of the third is 2 (tokyo.html).
So, $segments[0] = asia
In the example I wrote in my previous post we check the value of this first segment. If it is "asia" we know that the user sees category with seotitle "asia" and we can display him the template differently. If the value of the first segment is something else we use a different style for the template. Got it?
URI segments can be retrieved with $segments = eFactory::getURI()->getSegments();
-
I created a directory under templates named aglaea. I noticed that nautilus does not see the template and then checked phpmyadmin and verified that the template has to be loaded into the db.
Is there a way that I can test templates using a url as we can in 2009.x without loading it into the db?
-
You must install in the template, or manually add an entry in the corresponding database table (elx_templates).
-
Only one more question for the moment. You wrote
case 'user': $layout = '3columns.php'; break;
case 'search': 'something': $layout = 'nocolumns.php'; break;
So, in what folder / directory will any or all php pages that are created such as nocolumns.php go?
-
You can have them wherever you like. In my example above a have them in the template's root folder:
include(ELXIS_PATH.'/templates/mytemplate/'.$layout);
So, for the "nocolumns.php" case templates/mytemplate/nocolumns.php
-
Hi,
I'm creating a template structure that allows unique templates, based on this example, thanks to datahell. I am almost successful with it.
However I encounter one problem not sure how to solve.
So, directory example:
templates/unique/css/template.css
templates/unique/index.php
templates/unique/frontpage.php
templates/unique/common.php
So, when in frontpage (index of site) it will show frontpage.php else will show common.php unless otherwise specified. index.php holds all main code of html and elxis variables. All special files like frontpage.php and common.php (or any new template files) are code included between the <body> and </body> tags using this....
elxisLoader::loadFile('templates/unique/'.$tps2);
$tps2 being the name of special template files.
Everything works fine as test. Problem is when I put in modules or elxis instances such as:
<?php $eDoc->modules('language', 'none'); ?>
or
<?php $eDoc->modules('left'); ?>
I get this on frontend of website:
[:head:] [:replmark2:] [:replmark3:]
Any idea what am I missing or how to fix it? Thanks! Need to fix this then I can share.
-
Dont use the elxisLoader to include the template's file, elxisLoader is for PHP libraries. If you do so you have to work different on these files.
Use php's standard include function:
include(ELXIS_PATH.'/templates/unique/'.$tps2);
Everything else is fine, go on!
-
Dont use the elxisLoader to include the template's file, elxisLoader is for PHP libraries. If you do so you have to work different on these files.
Use php's standard include function:
include(ELXIS_PATH.'/templates/unique/'.$tps2);
Everything else is fine, go on!
I see, thanks datahell!
Let me do a few testings and will share with community for better improvement. Is there a place I can share and give support for the template or is only through EDC?
Thanks.
-
Hey datahell,
I tried your suggestion and was still receiving same errors as before. I tinkered with it some more and I found this solution for it.
I had to copy this code and put in new file (header.php) in templates/unique/header.php
<?php
defined('_ELXIS_') or die ('Direct access to this location is not allowed');
// get the Elxis libraries we are going to use
$eLang = eFactory::getLang();
$eDoc = eFactory::getDocument();
$elxis = eFactory::getElxis();
$tplbase = $elxis->secureBase().'/templates/unique';
elxisloader::loadFile('templates/unique/includes/unique.class.php');
$unique = new templateUnique();
// display the document type before the html tag.
echo $eDoc->getDocType()."\n";
?>
Then in ALL template files, special or index.php I need to add this to top of page.
<?php include('header.php'); ?>
It works. please advise is this a good/safe approach for the template? Thanks!
-
Elxis Document parses standard template files only (index.php, inner.php, mobile.php, error.php, error404.php, alogin.php, etc...). If you include other files make sure that the module positions you declare are directly accessible by the Elxis Document parser. In this case your, for example, index.php file should only include the custom template file and do nothing else. Inside the custom template file you should write what you would normally do in your index.php file if you hadn't the extended functionality.
in index.php:
if ($media == 'mobile') {
include(ELXIS_PATH.'/templates/mytpl/layouts/mobile.php');
} else if ($media == 'tablet') {
include(ELXIS_PATH.'/templates/mytpl/layouts/tablet.php');
} else if ($media == 'webtv') {
include(ELXIS_PATH.'/templates/mytpl/layouts/webtv.php');
} else {
include(ELXIS_PATH.'/templates/mytpl/layouts/desktop.php');
}
OR
in index.php:
if ($page == 'frontpage') {
include(ELXIS_PATH.'/templates/mytpl/layouts/frontpage.php');
} else if ($page == 'category') {
include(ELXIS_PATH.'/templates/mytpl/layouts/category.php');
} else if ($page == 'contact') {
include(ELXIS_PATH.'/templates/mytpl/layouts/contact.php');
} else {
include(ELXIS_PATH.'/templates/mytpl/layouts/standard.php');
}
OR any other separation you like.
in your index.php you should detect the proper value of the separation rule ($media, $page, etc...) you will use later in your if statements.