The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Konstrukt::Doc::Templating - Using templating to create static web sites

DESCRIPTION

This framework cannot only be used to create dynamic websites but also to create modular and maintainable static websites. The template plugin can be used to modularize your website:

You are enouraged to encapsulate your web site components that are used in several places in templates, which then can be reused to avoid redundancy. A website usually consists of several components, that are used in many pages (layout, navigation, message boxes, tables, ...).

Each template consists of static text and variable parts, that can be substituted on the usage of the template.

BASIC TEMPLATE EXAMPLE

The simplest example for this is the encapsulation of the layout. The layout will probably be the same across all your pages, so reuse of the layout instead of copy and paste is a good idea. With Konstrukt you will do it like that:

layout.template (define the layout and the variable fields):

        <html>
        <head><title><+$ title +$>Default Title<+$ / $+></title></head>
        <body>
                <div id="navigation">
                        Navigation: (Some Links...)
                </div>
                <div id="content">
                        Content: <+$ content $+>No content<+$ / $+>
                </div>
        </body>
        </html>

Where title and content are variables, that will be replaced by page-specific values. The text between the variable tags is the default for the variable, if no value is specified.

index.html (use the layout and replace the variable fields with custom content):

        <& template src=“layout"layout.template" &>
                <$ title $>My web page<$ / $>
                <$ content $>
                        Some great content
                <$ / $>
        <& / &>

So in every page you only specify the essential data like the title and the content of this page. Recurring data like the layout, which is wrapped around your content, will be cleanly separated in the template files.

Result (some whitespaces may vary...):

        <html>
        <head><title>My web page</title></head>
        <body>
                <div id="navigation">
                        Navigation: (Some Links...)
                </div>
                <div id="content">
                        Content: Some great content
                </div>
        </body>
        </html>

TEMPLATE SYNTAX

Basically you define some slots in your template using <+$ field_name $+> and <+@ list_name @+> tags and fill them using a <& template &> tag containing <$ field_name $>value<$ / $> and <@ list_name @>list_fields...<@ / @> tags that define the content to fill the slots.

For a complete reference of the templating syntax see Konstrukt::Plugin::template.

AUTHOR

Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.

This document is free software. It is distributed under the same terms as Perl itself.

SEE ALSO

Next: Konstrukt::Doc::FunctionPlugins

Previous: Konstrukt::Doc::Basics

Parent: Konstrukt::Doc

See also: Konstrukt::Doc::PluginList

1 POD Error

The following errors were encountered while parsing the POD:

Around line 46:

Non-ASCII character seen before =encoding in 'src=“layout"layout.template"'. Assuming CP1252