Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  TEMPLATE::MAGIC::QUICKSTART (3)

.ds Aq ’


Template::Magic::QuickGuide - A quick start for Webmasters


Quick Start for Webmasters


If you are a webmaster you don’t need to know perl in order to completely customize the output of any perl script that uses Template::Magic: you have just to edit the templates that the perl script uses, and you will have the full power on the script output. Well... the full power the perl programmer decided to give you ;-).


Templates are simple files used by the Template::Magic system in order to produce the output. Depending on the application, a template might be a text, html, xml, or any other type of file. Usually the template is composed by static text (i.e. the text that will never be changed by the application), and a few delimited zones (labels or blocks), that will be substituted by the application with dynamic data produced by the program. The merging of the static text and the program data will produce the output of the program.

This is a very simple template file:

    City: {city}
    Date and Time: {date_and_time}

where {city} and {date_and_time} are just zones (labels) that the application recognizes and replaces with some real runtime values. The remaining text is static text which will be included verbatim in the output.

The following may be an output:

    City: NEW YORK
    Date and Time: Sat Nov 16 21:03:31 2002

    Zones: Labels and Blocks

A ’zone’ is a special delimited place in the template, that the Template::Magic system recognizes as a zone. Depending on the implementation decided by the programmer, the zones of each application may be delimited by a different set of characters. Usually the default delimiters are { } or <!--{ }--> (which are default delimiters included in HTML comments, very handy in HTML WYSIWYG editors).

A zone may have a content or not. A zone with no content is also a label, while a zone with content is also a block:

    a label: {identifier}
    a block: {identifier} content of the block {/identifier}

Identifiers are case sensitive and are defined by the programmer. He should provide a list of recognized labels and block, along with a description of each zone.

    Repeating blocks

Oftenly an application is required to produce lists. It can do so by implementing a repeating block. The content of the repeating block will be parsed and the included labels and blocks will be substituted with the actual data as many time as necessary in order to produce the full list output:

      City: {city}
      Date and Time: {date_and_time}

The following may be an output:

    City: NEW YORK
    Date and Time: Sat Nov 16 21:03:31 2002
    Date and Time: Sun Nov 17 18:21:40 2002
    City: MIAMI
    Date and Time: Mon Nov 18 16:38:16 2002

    the NOT_* block

For any label or block you can use a NOT_* zone (where ’*’ stands for the zone id) which will automatically be printed if the zone is not printed, or wiped out if the zone is printed.

      City: {city}
      Date and Time: {date_and_time}{NOT_date_and_time}N/A{/NOT_date_and_time}
      No visit to report

The following may be an output:

    City: DENVER
    Date and Time: N/A
    Date and Time: Sun Nov 17 18:21:40 2002
    City: MIAMI
    Date and Time: Mon Nov 18 16:38:16 2002

The following may be another output:

    No visit to report


You can inlude a template or a static text file by using 2 special lables: INCLUDE_TEXT and INCLUDE_TEMPLATE. The include text will include verbatim the text found into the file, while INCLUDE_TEMPLATE will parse the file first, substituting labels and blocks with actual data.

    {INCLUDE_TEMPLATE /templates/temp_file.html}
    {INCLUDE_TEXT /templates/text_file.html}

Paths are relative to the current template.

    Customizing a template

You can customize all the static text in any template, you can also omit or move any label or block inside any template. You can split a template into chunks and include each chunk with an INCLUDE_TEXT or an INCLUDE_TEMPLATE label, or you can join different included templates chunk into a single template.

In special cases, when the programmer implemented this possibility, you can also pass some custom parameters to some custom labels in order to further customize the output. Anyway, the label and block definition along with the production of the dynamic content is always controlled by the application.


attributes string The attributes string contains every character between the end of the label identifier and the end label marker.

<B>NoteB>: The attributes are a special implementation decided by the programmer for special resons.

block A block is a template zone delimited by (and including) a label and an end label:

    | LABEL |      CONTENT      | END_LABEL  |

Example: <B>{my_identifier} content of the block {/my_identifier}B>

where {my_identifier} is the LABEL, content of the block is the CONTENT and {/my_identifier} is the END_LABEL.

end label An end label is a string in the form of:


Example of end label : <B>{/my_identifier}B>

where { is the START_MARKER, / is the END_MARKER_ID, my_identifier is the IDENTIFIER, and } is the END_MARKER.

identifier A label identifier is a alpha-numeric case-sensitive name that must be implemented by the application.
illegal blocks Each block in the template can contain arbitrary quantities of nested labels and/or blocks, but it cannot contain itself (a block with its same identifier), or cannot be cross-nested.

<B>Legal blockB>: {block1}...{block2}...{/block2}...{/block1}

<B>Illegal auto-nested blockB>: {block1}...{block1}...{/block1}...{/block1}

<B>Illegal cross-nested blockB>: {block1}...{block2}...{/block1}...{/block2}

If the template contains any illegal block, unpredictable behaviours may occur.

include label An include label is a label used to include a template or static text file. The identifier must be ’INCLUDE_TEMPLATE’ of ’INCLUDE_TEXT’ and the attributes string should be a valid path. Paths are relative to the current template.

Example: <B>{INCLUDE_TEMPLATE /templates/temp_file.html}B> Example: <B>{INCLUDE_TEXT /templates/text_file.html}B>

label A label is a string in the form of:


Example: <B>{my_identifier attribute1 attribute2}B>

where { is the START_MARKER, my_identifier is the IDENTIFIER, attribute1 attribute2 are the ATTRIBUTES and } is the END_MARKER.

<B>NoteB>: The attributes are a special implementation decided by the programmer for special resons.

markers The markers that defines a labels and blocks. These are the default values of the markers that define the label:

    END_MARKER:     }

The default marker used in HTML environment (e.g. <!--{identifier}-->):

    START_MARKER:   <!--{
    END_MARKER:     }-->

Each application may define a different set of markers.

nested block A nested block is a block contained in another block:

    |   CONTAINER_BLOCK    |
    |  +----------------+  |
    |  |  NESTED_BLOCK  |  |
    |  +----------------+  |

<B>{my_nested_identifier} content of the block {/my_nested_identifier}B>

where all the above is the CONTAINER_BLOCK and {my_nested_identifier} content of the block {/my_nested_identifier} is the NESTED_BLOCK.

output The output is the result of the merger of runtimes values with a template
template A template is a text content or a text file (i.e. plain, HTML, XML, etc.) containing some label or block.
zone A zone is an area in the template that must have an identifier, may have an attributes string and may have a content. A zone without any content is also called label, while a zone with content is also called block.


X 2004-2005 by Domizio Demichelis (<>)

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.


Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 229: Non-ASCII character seen before =encoding in ’X’. Assuming ISO8859-1
Search for    or go to Top of page |  Section 3 |  Main Index

perl v5.20.3 TEMPLATE::MAGIC::QUICKSTART (3) 2006-09-15

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.