wiki:SmartyAdditions

ExiteCMS v8 : Smarty Additions


ExiteCMS is a template driven framework.

When a page is requested, the framework does a lookup of the page in the website content tree, checks which theme and template is defined to display the page, loads the template and displays it.
From this point, the template takes over. It does that by callbacks into ExiteCMS, to fetch the output defined for all sections defined in the template. For this purpose, several new functions have been created for the Smarty template engine.

The documentation for the standard Smarty functions can be found  here.


Block functions

{ if_section }

The purpose of this block function is to test if there are elements defined within a specific named template section, and if so, process the template contents of the block. This allows template designers to test for the availability of element output in the template, and make design decisions based on the presence or absence of output.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringyesn/aName of the element section in the template
minintegerno1Minimum number of elements that need to be defined
exactbooleannofalseIf true, the min value must be met exactly
delaybooleannofalseIf true, delays processing this section untill all other sections are processed

Example

{if_section name="center" min=1}

   <h2>Print this if there is at least one center element defined that has output</h2>

{/if_section}

The name of the element section can also be an expression. This comes in handy if you want to check or evaluate multiple template sections at once. Both arithmetic and logical operators are supported. Brackets to alter the evaluation are currently NOT supported!

Example

{if_section name="left + right" min=1}

   <h2>Print this if there is at least one element defined in both the left and the right section that has output</h2>

{/if_section}


{ has_task_assigned }

The purpose of this block function is to allow template designers to make output conditional on if a task is assigned to the current user or not.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
taskstringyesn/aName of the task to check
modulestringnon/aOptionally, the name of the module that defined the task
valuemixednon/aOptionally, the constraint value to check
varstringnon/aIf specified, a template variable with this name will be created, and set to 1 if the task was assigned, 0 if not

Example

{has_task_assigned task="MY_TASK" module="MY_MODULE"}
   <h1>This task is assigned to me!</h1>
{/has_task_assigned}


{ has_role_assigned }

The purpose of this block function is to allow template designers to make output conditional on if a role is assigned to the current user or not.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
rolestringyesn/aName of the role to check
descriptionstringnon/aOptionally, a descriptive reason for checking. This will be used when access violations are logged
varstringnon/aIf specified, a template variable with this name will be created, and set to 1 if the task was assigned, 0 if not

Example

{has_role_assigned role="MY_ROLE"}
   <h1>This role is assigned to me!</h1>
{/has_role_assigned}


{ buttons }

The purpose of this block function is to create an inline or block elements in which you can define buttons using the {button} function or anchors using the {anchor} function. If you use the {anchor} function the link will be styled as a button, but it will still behave as a link.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
stylestringnon/aAny additional styling you want to apply to the HTML element
inlinebooleannofalseIf false, a <div> will be generated. If true, a <span> is used

Example

{buttons style="margin:10px 0px;" inline=no}
	{button name="Save" type="submit" image="button_save.png" class="" title="Save the data" text="Normal" disabled=no accesskey="S" tabindex=1}
	{anchor link="http://www.google.com" image="google.png" title="Go to google" new=yes}
{/buttons}



Functions

{ anchor }

The purpose of this function is to create an ExiteCMS compliant link. Several styling options are available.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
textstringno*falseText used on the link.
supports the syntax 'lang:[line]:[section]' to get localised text
imagestringno*n/aFilename of an image. If no path is specified, it is loaded from the theme images directory
linkstringyesn/aURL. If it is a relative link, the link will be converted to an absolute link
titlestringnon/aOptional anchor tag title
supports the syntax 'lang:[line]:[section]' to get localised titles
segmentsstringnon/aAny URI segments you want add to the link
onclickstringnon/aOptional javascript to be executed when you use clicks the button
stylestringnon/aAny additional style you want to apply to the HTML element
newbooleannofalseif true, clicking the link will open a new window
scriptbooleannofalseif true, the URL passed contains javascript code
confirmstringnon/aif specified, this adds a javascript confirm() to the onclick of the link. This string is the confirm question being displayed
supports the syntax 'lang:[line]:[section]' to get localised titles

*) Note that either 'text' or 'image' is required.

Example

{anchor text="this is a link" link="javascript: history.go(-1);" script=yes}


{ asset }

This function allows you to load assets from your template.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
idstringnon/aIf specified, the tag ID of the HTML tag (not for 'js' and 'css' assets)
namestringyesn/aFilename of the asset. This name must be a filename only, no path information may be included
typestringyesn/aType of asset being loaded. Currently, it supports 'css', 'js', 'icons' and 'images'
classstringnon/aAny additional class you want to apply to the HTML element (not for 'js' and 'css' assets)
stylestringnon/aAny additional style you want to apply to the HTML element (not for 'js' and 'css' assets)
onclickstringnon/aOptional javascript to be executed when you use clicks on the asset (not for 'js' and 'css' assets)
titlestringnon/aText for the asset title tooltip (not for 'js' and 'css' assets)
supports the syntax 'lang:[line]:[section]' to get localised titles
modulestringnon/aName of the module that provides the asset. If not given, ExiteCMS will check the assets of the currently loaded module and the currently loaded theme

Example

{asset name="image.png" type="images"}
{asset name="red.css" type="css"}

This produces (if the current theme is 'ExiteCMS8'):

<image src="/assets/themes/ExiteCMS8/images/image.png" />
<link href="/assets/themes/ExiteCMS8/css/red.css" rel="stylesheet" type="text/css" />


{ button }

The purpose of this function is to create an ExiteCMS compliant button. Several styling options are available.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringyesn/aName of the button. This is the name returned by the form_button() function of the Form_validation library
idstringnon/aIf specified, the tag ID of the button
textstringyesfalseText used on the button.
supports the syntax 'lang:[line]:[section]' to get localised text
typestringnobuttonIf specified, has to be button, sumbit or reset
imagestringnon/aFilename of an image. If no path is specified, it is loaded from the theme images directory
classstringnon/aAny additional class you want to apply to the HTML element
stylestringnon/aAny additional style you want to apply to the HTML element
titlestringnon/aText for the button title tooltip
supports the syntax 'lang:[line]:[section]' to get localised titles
disabledbooleannofalseif true, the button will be disabled
accesskeystringnon/aAny access key you want to assign to the HTML element
tabindexintegernon/aAny tabindex you want to assign to the HTML element
onclickstringnon/aOptional javascript to be executed when you use clicks the button

Example

{button name="Save" type="submit" image="button_save.png" class="" title="Save the data" text="Normal" disabled=no accesskey="S" tabindex=1}
{button name="normal" type="button" class="positive" title="normal type button" text="Normal" disabled=no accesskey="N" tabindex=2 onclick="alert('hello there!');"}


{ captcha }

The purpose of this function is to display a captcha. The ExiteCMS administration has the ability to select one of the captcha modules available for ExiteCMS, or to disable captcha's all together (p.e. when building an intranet website, where all users are known and/or can be trusted).

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringnononeName of the captcha to load. If it doesn't exist, this function defaults to 'none'. Note that you should use '$_env.config.captcha' to use the administrator defined captcha.
idstringnon/aIf specified, the tag ID of the captcha image
stylestringnon/aAny additional style you want to apply to the captcha image
titlestringnon/aText for the refresh button title tooltip (if present)

Example

{captcha name=$_env.config.captcha id="validate" title="Click to refresh the capcha image" style="margin-left:10px;"}


{ editor }

The purpose of this function is to load a WYSIWYG editor. The ExiteCMS administration has the ability to select one of the editor modules available for ExiteCMS, or to select 'none' to use standard HTML textarea's for editing.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringnononeName of the editor to load. If it doesn't exist, this function defaults to 'none'. Note that you should use '$_env.config.editor' to use the administrator defined editor
idstringnon/aIf specified, the tag ID of the editor HTML element used
typestringnon/aType of editor to load. [currently not used]
modestringnobasicMode in which the editor should be loaded. Currently supported are 'basic' and 'full'. What this means is defined by the editor module creator, 'basic' is usually limited in functionality
stylestringnon/aAny additional style you want to apply to the editor HTML element used
valuestringnon/aDefault content to pass on to the editor (i.e. the contents of the field to be edited

Example

{editor name=$_env.config.editor type="textarea" id="reason" style="width:95%;" value="Please edit me!"}


{ html_header }

The purpose of this function is allow module elements to add javascript or css files to the &lt;head> section of the page. This function uses the same logic as the { asset } function to locate the file to load.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringyesn/aName of the file to load. Use this consistently, as it is used to detect duplicate load requests
typestringyesn/aType of file being loaded. Currently, it supports 'css', 'js' and 'editor'
valuestringyesn/aFilename of the file. This name must be a filename only, no path information may be included

Example

// add the script 'mootools-1.2-core.js' to the <head> section of the page.
{html_header type="js" name="mootools_core" value="mootools-1.2-core.js"}


{ html_select_country }

The purpose of this function is to create a dropdown field from which you user can select a country name. This function is locale aware, and will return a country code from the ISO-3166 table.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringyesn/aName of the form field for this dropdown
idstringnon/aIf specified, the tag ID of the &lt;select> tag
classstringnon/aAny additional class you want to apply to the HTML element
stylestringnon/aAny additional style you want to apply to the HTML element
defaultstringnon/aAny valid country code from the ISO-3166 table, or '--' for an unknown country
titlestringnon/aText for the HTML element title tooltip
supports the syntax 'lang:[line]:[section]' to get localised titles

Example

{html_select_country name="country_id" id="country_id" default="US" class="styled" style="margin:10px;"}


{ html_select_date }

This function is a modified version of the default Smarty function. You will find the syntax in the Smarty documentation.

The following extra parameters or parameters with added functionality are available to this function:

Attribute NameTypeRequiredDefaultDescription
field_orderstringnon/aIf not specified, the function uses the current date and time locale to determine the field order
allow_zerobooleannon/aIf specified and TRUE, a zero timestamp causes all fields to be displayed as '--', if FALSE, a zero timestamp defaults to now()


{ html_select_timezone }

The purpose of this function is to create a dropdown field from which you user can select a timezone. This function is locale aware, and will return CodeIgniter Timezone codes.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringyesn/aName of the form field for this dropdown
idstringnon/aIf specified, the tag ID of the &lt;select> tag
classstringnon/aAny additional class you want to apply to the HTML element
stylestringnon/aAny additional style you want to apply to the HTML element
defaultstringnoUTCAny valid timezone code from the CodeIgniter Date Helper timezone reference
titlestringnon/aText for the HTML element title tooltip
supports the syntax 'lang:[line]:[section]' to get localised titles

Example

{html_select_timezone name="tz_id" id="tz_id" default="UTC" class="styled" style="margin:10px;"}


{ load_lang }

{load_lang} is the Smarty equivalent of the CodeIgniter $this->load->lang() function as provided by the Language Library. It is used to load a language file from within a template.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringyes""Name of the language file to load
idioomstringno""Language to load. If not specified, it defaults to the currently selected language
modulestringno""Name of the module to load this language file from. If not specified, the file is loaded from the current active module (i.e. to which the template belongs to)

Example

// this loads ./modules/my_exitecms_module/languages/en/my_module_lang.php
{load_lang name="my_module" module="my_exitecms_module" idiom="en"}


{ lang }

{lang} is the Smarty equivalent of the CodeIgniter lang() function as provided by the language_helper. It is used to retrieve a language string from within a template.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
linestringyesn/aKey (language line) of the language string to retrieve
idstringno""Name of the label ID. If set, the function returns the string in a HTML <label> tag
sectionstringnon/aName of the language file section the key must be looked up in
assignstringnon/aIf defined, assign the result to this variable, do not output it
ignorebooleannofalseIf TRUE, no error is produced if the language line was not specified

Example

{lang line="username" section="login_panel"}: <input type="text" name="username" value="" size="25" />

Note that if the line was specified but not found, and ignore is FALSE, the line will be returned enclosed in a black on yellow colored <span>. this makes easy to see that you have made a mistake, either in your template, or in your language file.


{ load_section }

{load_section} is a function that will ask ExiteCMS to send the output of all modules within a specific named template section. This allows template designers full flexibility to where in their template they want to place modules, which modules are placed there, and how many.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
namestringyesn/aName of the module section in the template
typestringno*n/aType of modules allowed in this position
modulestringno*n/aName of a specific module to load
maxintegernounlimitedMaximum number of modules that are allowed to output
titlebooleannoyesIndicates whether or not titles are displayed at this position
templatestringno"none"Chrome template used to render output at this position

*) Note that either 'type' or 'module' is required.

Example

{load_section type="panel" name="center" max=3 template="xhtml"}


{ sorttable }

This function is deprecated


{ ssprintf }

This function is the Smarty equivalent of the PHP sprintf() function.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
formatstringyesn/asprintf() compliant format string
argumentsmixedyesn/aArguments for the sprintf() function

Note that, like with the sprintf() function, the order of the variables is important! The names of the variables are not used, you only have to make sure they are unique.

Example

{ssprintf format=$string var1=$var1 [var2=$var2 [...]]}


{ tablenavigation }

This function creates a standard table navigation section, for pagination purposes.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
rowsintegeryesn/atotal number of rows in the table
firstintegeryesn/anumber of the first row currently displayed in the table
intervalintegernonumber of rows displayed per page
rangeintegerno3navigation range, number of pages available left and right of the current page indicator
ajaxstringnon/aname of the javascript function to be called to process the json data recieved [not implemented yet]

Note that this function uses the current URI to create the URI used to link to new pages. This way any additional parameters in the URI, like for example sort field and sort order, will be maintained without extra programming. The new top row number will be added to the URI as '/start/<value>'. If this parameter already exists, its value will be replaced by the new value.

The HTML for the navigation block will be generated by a template called 'tablenavigation.tpl', located in the theme template directory. If the current theme doesn't have it, it will be loaded from the ExiteCMS8 default theme. This allows theme designers to create their own template to style this navigation block.

Example

{tablenavigation rows=$rowcount first=$rowstart range=3}


{ variable }

This function is deprecated



Modifiers

| span

The purpose of this modifier is to enclose a string in a <span> tag, optionally assigning it a class name. It is mainly used in combination with the variable replacement functions (sprintf alike) of the { lang } function.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
classstringnon/aAny class you want to assign to the span element

Example

{lang line="l1_cmsversion" section="exitecms_administration_dashboard" ver=$_env.version|span:"highlight" rev=$_env.revision|span:"highlight"}

this produces:

This website is currently running ExiteCMS version <span class="highlight">8.0</span>, revision <span class="highlight">356</span>.


| date_format

The purpose of this modifier is apply a format string to a UNIX timestamp, so that it can be displayed.

The following parameters are available to this function:

Attribute NameTypeRequiredDefaultDescription
formatstringnoYYYY-MM-DD HH:MMAny strftime() compatible format string, or any of the predefined strings from the table below
defaulttimestampnonow()Optionally, you can pass this modifier a default timestamp value.

ExiteCMS defines a list of standard format strings, which can be used in templates. The format for this strings can be defined by the ExiteCMS administrator, via the 'Configuration, Date and Time' menu option. These strings are:

Format stringDescription
shortdateUse it where there is not a lot of space available. A shortdate is in a format like "20090323" or "23-03-09"
longdateUse it where you have more space. A longdate can be formatted as "Sunday, March 23rd 2009"
shortimeUse it where there is not a lot of space available. A shorttime is usually formatted as "HH:MM"
longtimeA longtime format usually includes seconds, and/or other additions, p.e. "12h, 17m, 10s"
shortdatetimeA combination of shortdate and shorttime
longdatetimeA combination of longdate and longtime

It is encouraged that you use the predefined strings as much as possible, to give the ExiteCMS administration control over the date and time formats.


Example

{$timestamp|date_format:"shortdate"}