The view

The view

What are view files?

The view files contain the actual view of a part and layout.

The view file (view.tmp) is a special HTML file that contains not only the HTML code but also the different values of the controller part. For combining these values in the view the use of the H4 Temp class is needed. This class is used in the controller part to combine the model. For the special events in a view file are braces used.


Variables are mostly being used for placing data from the control file into the view.

To insert a predefined variable use : {$variable_name}. Where variable_name is the predefined name. When using a variable from an array use a point to separate the array's level. For example the PHP array variable $aData['name'] will be in the template file {$}.

Further option is to adjust a variable by a PHP plugin. For example the plugin truncate truncates a string value. To use an extra plugin with a variable use the pipe symbol. For example to use the truncate function with the variable sTitle write {$sTitle|truncate(48)}. You can use multiple of functions with one variable separating every function with a pipe symbol.


This topic explains the functions that can be used within a view file.

If, elseif and else

Just like in PHP you can make the use of if's and else's. Only difference is that you capture them in braces and that unlike as in JavaScript or PHP you dont open or close an if statement with a brace. So for example the state if variable sTitle got a value show sTitle will be as followed:

{if ($sTitle)}{$Title}{/if}

As you can see if statements are always closed by the {/if} function.


A new function that is similar like the foreach function in PHP is the loop function. With this function parts of a template can be repeated for filling for example a list. Loops are being used as followed:


In this example the array aList is being looped. If you use a simple array (key => value) then the loop variable would be $aList.value. The variable key ($aList.key) can be used to identify the current position / key of the array.


The command {template(template_name)} are in the case of theme engineering only used to connect and position the different parts within an layout. So for example if a layout contains to parts (banner and content) we place in the layout view the code's {template(banner)} and {template(content)} in the parts of the HTML where we want to view these parts.


Literals are being used to ignore a part of the template code. For example you don't want the braces in a JavaScript code being interpreted as a template code. The usage of literals are as followed:

{literal} This code {$somevariable} is being ignored! {/literal}


Constants are powerful variables that can be used throughout the theme.

A constant variable is a variable that can be used in the CSS, JavaScript and template file. However note that the variable only works within a CSS and JavaScript file when the option oneJs and oneCss is set true. The constant name must always be written in capitals, starting and ending with the percentage sign. So for example: %CONSTANT%. Read more about this option in the controller section.

Default constants are:

H4CLIENT : This is the client URL.
H4ROOT : This is the H4 framework root URL.
H4SHARED : The H4 shared URL.
H4VERSION : The H4 framework version.
VERSION : The H4 temp engine version.
YEAR : The current year.

Note that these constants aren't written with the percentage sign since this will replace the name with value.