YaPIG templates

Since 0.65 version, YaPIG supports full template configuration, so you can create your own YaPIG look and integrate it on your web design. In this little guide you will learn the template system of YaPIG and how to modify it even if you dont know the PHP language (here it will be explained all you need to know). HTML knowledge is recommended.

Template System

When YaPIG needs to print some HTML contents, it just defines a global variable accesible from any PHP file. In YaPIG config file (config.php) there is a variable called $TEMPLATE_DIR that contains the directory where the yapig template is stored. As default it is set to 'template/default/' (remember that this value must end with '/' character).

What is in the $TEMPLATE_DIR? Well, obviously, the template files :D. Each file has a format like this:

	 this is a PHP comment and will be ignored.

        echo <<<NAME

        <!-- Here goes HTML code with som PHP variables -->
	    <img src="{$D_VARNAME}" alt="$D_VARNAME2"/>
	    <b>{$I_TEXT}:</b> $D_VARNAME3<br />


Each file is a PHP file containing a HEREDOC Variable, this kind of variables are delimited by the two tags NAME in this case. Inside these kind of PHP variables you can write HTML code and even show the content of other PHP variables. In general, PHP variables are identified by the '$' character.

We have defined two kinds of variables whitch the only difference is the logic way they are used. Ones have the $D_ prefix, this means that they store data information. The others identified by the $I_ prefix means that they are interface messages. These interface messages are set this way for internationalization. For example: the contents of the variable $I_VISITS may be set to 'Visits' if you are using the English languaje or 'Visitas' if your language is Spanish.

Note that some variables are surrounded by the '{' and '}' characters, these are optional, just for avoiding ambiguous names.

What can I modify?

As you can see, this system is based in HEREDOC PHP variables. You can modify the HTML code inside each HEREDOC variable. The names of the "normal" PHP variables embedded in them cannot be modified, if you do this their value won't be shown. As well, the names of the php files in the $TEMPLATE_DIR cannot be modified.

The names of the files in $TEMPLATE_DIR are significative, so their function is easily guest by the name. They also contain a PHP comment that resumes their function and where are they used inside the YaPIG source code.

In addition to this, if you take a look at the default HTML code generated by YaPIG you will see HTML comments like these:

<!-- face_begin BEGIN-->

   Some HTML code 
<!-- face_begin END-->

These two comments delimit the BEGINNING and END of the face_begin.php template file.