{PROJECT} ../../template/doc.en.ini {GRAFIK_LINKS} $home/gifs/li_phpcms.gif {LOGO_1} $home/gifs/cmslogo1.gif {LOGO_2} $home/gifs/cmslogo2.gif {MENU} 00.08.10.02 {TITEL} Templates {CONTENT}

- Description of Templates
- Usage of the "$home" - variable in templates
- An example
- What are sub templates?
- Why use sub templates?

Description of Templates

Templates are like those templates from Word for standard uses. A template is a normal HTML file with substitute symbols in it.

The substitute symbols are then replaced by the real contents, which are under the same field name in the content files. This splits the content from the layout of a website.

We do not consider now the project file and the menus. We treat these things in the area about content files.

Usage of the "$home" - variable in templates

Often you have to use the absolute path to graphics and/or style-sheets in your templates. If you plan to transfer your hole website to another server or simply change the directorys in your serverroot you run in problems with absolut paths. Then you must change each path in your template by hand. You can avoid this, if you use the "$home"-variable from your project-file. Simply set these variable in the path to your graphics and in future you have to change this path in only one place - the project-file.

A simple Template can look e.g. in such a way:

An example

<HTML>
<HEAD>
<TITLE>{TITEL}</TITLE>
</HEAD>
<BODY>
<H1>{TITEL}</H1>
<P>
{CONTENT}
</BODY>
</HTML>

We assume that in the first content page after the field {TITEL} the words: " my first homepage with phpCMS " and after the field designator {CONTENT} the words: " here is unnecessary talk, which is then inserted into the template.
You can use normal HTML tags for formatting. More intelligent it is however to use own TAGS to format a content.

The Parser replaces then with the call of the content page the substitute symbols in the Template with the values from the content page. That looks then in such a way:

<HTML>
<HEAD>
<TITLE>my first homepage with phpCMS</TITLE>
</HEAD>
<BODY>
<H1>my first homepage with phpCMS</H1>
<P>
here is unnecessary talk, which is then inserted into the template.<BR>
you can use normal HTML tags for formatting. More intelligent it is however to use own TAGS to format a content. </BODY>
</HTML>

As you can see: phpCMS is really easy to use!

What are Subtemplates?

If you have recurring HTML items in your templates, which should be alike however in all pages, you use at the best sub templates. Also within the same page (the same template) the same sub template can be used several times.

To use a sub template in a template file you must write a command like the following one:

> {TEMPLATE FILE="/homepage/templates/sub_template.tpl"}

Note:The line must be written just as, thus in large writing and with one blank after the keyword "TEMPLATE". If you use simple or no quotes, the sub template cannot be found.

You can use absolute or relative path definitions to call a template. Optionally you can use the variable $home. Some examples for valid commands to call a sub template:

> {TEMPLATE FILE="/homepage/templates/sub_template.tpl"}
> {TEMPLATE FILE="./sub_template.tpl"}
> {TEMPLATE FILE="$home/templates/sub_template.tpl"}

The variable $home is only defined if HOME is defined in the project file.

You can call sub templates also nesting, i.e. in a Sub Template a further Sub Template, but do not produce a recursion, when you try to call a sub template from the same sub template!

Except from these notes sub templates are just like normal templates!

Why use sub templates?

Take for example the copyright text on the top right of the authors page. This text is with one email-links provided. The text occurs on all pages of my homepage. I use different templates on my homepage.

If now my email address changes, I would have to modify the new address in each individual template if i would'nt use sub templates. With sub templates I only have to modify the email address in one sub template and this modification affects all pages.

Sub Templates are thus used for items in the side structure, which are same on all pages.