... Elxis version 2009.3 codename Aphrodite is out, download it from Elxis Download Center (EDC) ...

Template parameters

From Elxis Official Documentation

Revision as of 16:50, 25 June 2010 by Datahell (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search
Note: Template parameters is a new feature available in elxis 2009.1 and newer versions!


Elxis templates control the style and the layout of your site. The layout is controlled by the template's index.php file while the style by CSS files. Up to version 2009.0 to change something on the template you had to edit these files either via the Elxis templates manager or by downloading and editing at your computer.

On Elxis 2009.1 we introduced a new feature, the template XML parameters, which allow you to make changes on your template without touching the code! Template parameters works exactly like those for the Elxis modules, components or bots. The template parameters can be of any supported type (radio, list, select, text, imagelist, folderlist, spacer, etc). They can be used for any purpose the template design likes, setting a logo, changing colors, changing css file, loading modules, creating multilingual site titles, and more. The site administrator has only to set the parameters options to his desired values in order to modify the template. No more code hacking! Note that the template parameters are valid for all kind of templates, front-end template, administration templates and login screens.


Contents

Edit template parameters

Go to Elxis templates manager. From the list of the installed templates select the one you wish to edit and click Edit on the top right tool bar. On the next page you will see some information regarding the template (author, creation date, etc) as well as the template parameters. Change them at your will. If the template has no parameters then you will see an empty text area. Click Save when ready. You just changed the way your template looks without touching the code! Easy enough?

Editing template parameters


Template parameters for developers

Adding parameters in the template XML file.

Open the template's templateDetails.xml file. Just like on Elxis modules, bots and component create a section called params and for each parameter you wish to add create an entry with the name param. The following parameter types are supported by Elxis:

  • text Displays an input text field
  • radio Displays a group of radio boxes
  • list Displays a drop down selection list
  • mos_section Displays a drop down list of all content sections
  • mos_category Displays a drop down list of all content categories
  • mos_menu Displays a drop down list of all menu types
  • imagelist Displays a list of images in the given directory (attribute directory)
  • textarea Displays a textarea field (columns and rows are controlled by attributes cols and rows)
  • spacer Displays a separator
  • folderlist Displays a list of folders in the given directory (attribute directory)
  • database Displays a list of returning results from a database query. Available on Elxis 2009.2 or newer (read more).
Sample parameters in a template XML file
Sample parameters in a template XML file


Multilingual labels and description

You can have multilingual XML labels and description for your parameters either by using the premade "AX_" administration XML language variables or by defining your own "CX_" ones by using the cxlangdir parameter in the XML headers.

To see the available "AX_" language strings open file
administrator/language/english/english.xml.php

Sample declaration of the cxlangdir in templateDetails.xml

<cxlangdir>/templates/demotemplate/language</cxlangdir>
Inside the cxlangdir folder place your language files like this: english.php, italian.php, french.php, etc.

In each file declare your language strings as PHP constants having names starting from CX_
Example:
define('CX_DEMOTPL_HELLO', 'Hello world!');
Read also: Multilingual XML parameters


Adding parameters functionality on template index.php

OK, we have set up our parameters on the templateDetails.XML file and we are able to set their values from within Elxis administration console. We have now to work on the template index.php file in order for the parameters to change its layout and style. Open template's index.php file with a text editor. Here is how we get the parameters.

//Get the value of a parameter
//general syntax
$tplparams->get('parameter_name', 'default_value');
//example
$tplparams->get('csscolor', 'Red');
 
//Define the value of a parameter if it is not set
//general syntax
$tplparams->def('parameter_name', 'default_value');
//example
$tplparams->def('csscolor', 'Red');


Here is how we can add some real functionality on our template.

Example - Set the template logo

<?php 
//get the parameter value
$logo = $tplparams->get('logo', 'logo.png');
//check if the logo is not empty and the image file exists
if (($logo == '') || !file_exists($mainframe->getCfg('absolute_path').'/templates/demotemplate/logos/'.$logo)) {
   //in case logo is invalid, use the default one
   $logo = 'logo.png';
}
?>
<!-- display the logo image -->
<img src="<?php echo $mainframe->getCfg('live_site'); ?>/templates/demotemplate/logos/<?php echo $logo; ?>" alt="logo" />


On Elxis 2009.2+ use $mainframe->getCfg('ssl_live_site') instead of $mainframe->getCfg('live_site')


Sample implementations

Checkout how you can use template XML parameters to create a multilingual logo for your site.

Personal tools