From PMWH2 - PHPMyWebHosting's official wiki
Jump to: navigation, search

This project uses Smarty (actually 2.6.6), the template engine. You have to do the same. In order to help you a little I show you some simple things on how to use smarty in this project.

Create a template file

The template files reside in "templates/<template name>/modules/$act/$what.tpl". Your template file only contains HTML and Smarty command. Also static language code may be placed in it.

A minimum template file looks like this:

 1  {if $VALUE}
 2  <div class="test">
 3    {php}echo _CONSTANT;{/php}
 4  </div>
 5  <div class="test2">
 6     {VALUE}
 7  </div>
 8  {/if}


  • Line 1: You know if conditions. If the variable named "VALUE" is declared the following code will be executed.
  • Line 2,4,5,7: Some html code. You also can place tables and so on in the template.
  • Line 3: This is an embedded php function. It is surrounded with {php} and {/php} and the code included will be executed. Please use this only for language constants
  • Line 6: This is the smarty variable. It is filled with the value assigned within your code.
  • Line 8: closing if condition

With this knowledge you can write templates using smarty. If you want to explore all the functions of smarty (there are many more) take a look at

Use a template file

Before any content can be displayed you have to create a new Smarty object and assign your content to placeholders in the template files. At the end the complete template is fetched and added to the main template.

Here is some code example:

 1  <?php
 3  $s = new Smarty();
 4  $s->assign("VALUE",_SOME_CONSTANT);
 5  $main .= $s->fetch("modules/$act/$what.tpl");
 7  ?>

Description :

  • Line 3: Create a new Smarty object. Use "$s" in all your files. This is the easiest way and you do not have to invent new variable names.
  • Line 4: Assign the PHP-language constant "_SOME_CONSTANT" to the template variable "VALUE". In the resulting html code the variable "VALUE" is replaced with the content of the php constant "_SOME_CONSTANT"
  • Line 5: Add your template to the main template. Replace $act and $what with their values.


First add a header to your part. Use modules/header.tpl for this:

Put your menu name to it

If you only want to print out that a change or deletion was successfull, use the template file modules/result.tpl:

This variable used used to write some text to html
This variable needs pmwh_link("...") as assignment. Fill ... with your $act and $what definitions.