Introduction
Server Platform
Application Server
Content Generation
   Languages
   PageTree
   Pages
   PageType
   Elements
   Templates
   Callbacks
Class Library API
Manual Index

next | previous

Template Technique

The server provides a sophisticated template technique. Templates can be used to generalize a special design to remove a great deal of redundancy from the code. The idea is to split a page into smaller pieces, thus separating content from layout, static from dynamic, text from programming areas. Templates and generic elements can be imported and inherited from the page hierarchy tree.

Templates may be defined my a Perl template function or you can be stored in the content database. Use the 'DB-Template' or 'CGI-Template' generation type to choose.

For both generation types, templates types are used for grouping purposes. Templates then belong to a special template type and are referenced by their name and maybe the template number.

Simple template main element with embedded Maxscape API methods:

<!DOCTYPE html>
<html>
<head>
<title>
  @{[ $Page->ElementContent (Name => 'Title') ]}
</title>
<style type="text/css">
  @{[ $Page->ElementContent (Name => 'Category.CSS') ]}
  @{[ $Page->ElementContent (Name => 'Template.CSS') ]}
  @{[ $Page->ElementContent (Name => 'Page.CSS') ]}
</style>
</head>
<body>
  @{[ $Page->ElementContent (Name => 'Category.PageHead') ]}
  @{[ $Page->UserElementLoop() ]}
  @{[ $Page->ElementContent (Name => 'Category.PageTrailor') ]}
</body>
</html>

Template Types

For a given page generation type, Template Types are used to define a set of similar templates, elements and page generation functions. Different templates of a special template type may be used to implement different page designs/layouts.Template types may be user defined. Also some template types are predefined e.g. for the 'DB-Template' generation type:

ElementTemplate
The 'ElementTemplate' defines some standart elements and adds additional HTML code.
plainTemplate
No elements are predefined. The page is constructed only from the templates and elements.

T he templates may be configured via the appropriate entries in the configuration file. Set the variable WebServer.lookupWebServerTable to '1' or '2', to enable loading of data from the WEB_SERVER table.

Template Type Configuration

The page generation process can be configured via entries in the $::WebServer object. The ElementCallback entry defines the function to pre process elements during the elements fetch phase. The Function entry specifies the general template main loop function. If functions of the related names are defined via the application plugin, the internal default functions are overwritten.

Database templates are best located in the Templates sub tree of the servers page tree.

Default Template Elements

You can put the desired default database elements for a given type into a file located under the application server's tables/templates directory. The name of this file is the same as the template name. These elements are inserted, when a page is added by the administration surface.

Calling Functions in Templates

A general mechanism to call functions within database templates is, to embed Perl closures directly into the template code. To actually call the closures an additional evaluation of the code can individually set for each template and/or template element.

An embedded application function should take a reference to the 'maXscape::Page' object as the first parameter. Thus, all of the previously collected data are accessible in this function, including the database elements that contains the pages content.

Template Example

The following example is provided by the distributions 'Test' web server. The template name is 'simpleLayout':

<html>
<body bgcolor="#FFFFFF" text="#000000">

@{[ $Page->printElements() ]}

</body>
</html>

As you can see from this, the general page design is implemented by the template, thus reducing the static and therefor redundant HTML code by the number of pages minus one (the template!).

The source code of the example shows, that you can mix the HTML code with PERL closures. The closures executes the embedded function or method calls.

Adding Template Types to the Server

To add a new 'Template Type', add the name of the new 'Template Type' to the:

'Page.Type.<Generation Type>'

entry, via the 'server form' of the admin server. After this add the following entries to the WEB_SERVER table, using the server form or the 'MaxAdmin' tool:

Page.Type.<Generation Type>.<Template Type>

Page.Type.<Generation Type>.<Template Type>.ElementCallback

Page.Type.<Generation Type>.<Template Type>.Function

For example:
...
Page.Type.CGI-Template: 
                ElementTemplate
                plainTemplate
                Function
...
                  
Page.Type.CGI-Template.Function: 
                TableLayout(140)
                TableLayoutTopBottomMenu(145)
                defaultHomePage(171)
                defaultGroupHomePage(260)
                UserGroupTemplate(185)
                Simple(270)
                simpleTemplate(271)
                BodyFunction(279)
                FuntasyHome
                simpleHeadTrailorMenu
                  
Page.Type.CGI-Template.ElementTemplate.ElementCallback:   processElement
  
Page.Type.CGI-Template.ElementTemplate.Function:   PageStandardSkeleton


nextprevioustopbecome a membercontact © Maxscape