Store
Community Documentation

v3 Knowledgebase

Template tags in Phpfox

Hello all,

As you know the phpfox script uses some template tags that resemble the Smarty template engine. This doesnt mean that phpfox uses Smarty, we have our own template engine and do not use Smarty in any part of our script.
So, if you are a developer or designer and are wondering what templates are available here is a list that I hope you will find useful. Please remember that some of the tags require a template variable, like when you assign() to the template in the controller.

ldelim:
returns the left delimiter which by default is the left curly bracket: {
Example:
HTML:
this is a funky pointer -{ldelim}

produces:
this is a funky pointer -{


rdelim:
Same as before but applied to the right curly bracket.

php:
Wraps the content in <?php ?>
Example:
HTML:
This next is php {php} echo 'hello'; {/php}

produces
This next is php <?php echo 'hello'; ?>


for:
Acts like a normal php for cycle. Notice that we also use the {/for} tag here to tell where does the for end.
Example:
HTML:
I can count to 5: {for $i = 1; $i <= 5; $i++} {$i} {/for}

Produces:
I can count to 5: 12345


left_curly:
Sames a ldelim. This is the developer's preferred way for dealing with in line JS

right_curly:
Same as left_curly but with the right bracket: }

literal:
Wraps the content in a php echo, useful for JS.
Example:
HTML:
{literal}<script type="text/javascript">
	function myAlert(sValue){ alert(sValue);}</script>


foreach:
Wraps the content in a php foreach cycle. You require a template variable, assigned from a controller or block.
Example:
in the controller:
PHP:
$this->template()->assign('aVar' => array(1,2,3,4)); 

in the template:
HTML:
My numbers are {foreach from=$aVar item=iItem} {$iItem},

Produces:
My numbers are 1,2,3,4,


You can combine this with the tag foreachelse which acts in case the variable is empty, extending on the previous example:
in the template:
HTML:
My numbers are {foreach from=$aNonExistentVar item=iItem} {$iItem}, {foreachelse} missing

Produces:
My numbers are missing


if, else, elseif, /if:
Conditionals that match the php tags.
Example:
HTML:
{if !isset($aNonExistentVar)}
 My numbers are missing
{elseif !empty($aVar)}
 My numbers are present
{/if}


img:
Very useful tag as it shows images taking into account CDN and relative path.
Example displaying a theme specific image:
HTML:
Show the ajax loading image {img theme='ajax/small.gif'}

Example Show an image uploaded by a user:
HTML:
{img server_id=$aPhoto.server_id path='photo.url_photo' file=$aPhoto.destination suffix='_150' max_width=150 max_height=150 class="hover_action" title=$aPhoto.title}

Notice how there are extra params like max_width and title, anything you put here will be added as a value-pair entry in the img tag (<img title={$aPhoto.title)

editor:
Shows the text editor, it checks if wysiwyg is enabled and acts accordingly
Example:
HTML:
{editor id='text' rows='15'}

For more information see /include/library/phpfox/editor/editor.class.php function get()

value:
Used in forms, it helps to populate automatically fields already submitted. Used in conjunction with a controller to set an array in the template that has the values to use.
Example:
In the controller:
PHP:
$this->template()->assign(array('aForms' => array('sInput' => 'sValue'))); 

in the template:
HTML:
<input type="text" name="val[sInput]" value="{value type='input' id='sInput'}" size="25" id="sInput" />


select_date:
Useful to display date selectors.
Example:
HTML:
{select_date prefix='start_' start_year='current_year' end_year='+10' field_separator=' / ' field_order='MDY' default_all=true add_time=true time_separator='core.time_separator'}

This uses language phrases internally and if you look at the fields in that example you can figure out that the field_order controls the order, other values can also be changed from that example

select_location:
Outputs a drop down with the current countries.
Example:
HTML:
{select_location value_title='phrase var=core.any' name='country_iso_custom'}

The default value is defined in the value_title value, in this example it uses a language phrase (minus the curly brackets) to display "Any" as the first value.

select_gender:
Simple drop down with the available genders.
Example:
HTML:
{select_gender value_title='phrase var=core.any'}

It also uses value_title to define the first value in the drop down.