M.Zharkikh's personal site logo
Mail to site
Print version
News (RSS)
Smereka / For designers / Page templates

Smereka

For designers

Page templates

All content management systems use templates and Smereka in this regard is no exception. Page template in Smereka is a text document that contains a lookup field (smeretags) and (possibly) sections.

Most of templates used to generate HTML documents, and therefore contain static HTML code. But the templates technique can be successfully used to generate XML documents and other text documents.

Therefore, the development of template begins with a static HTML document that meets site design and includes all necessary additional objects such as style sheets, JavaScript files, graphic design elements.

The next step, this template should "revitalized" by smeretags (lookup fields) insertion.

Example template

Consider the following template:

<html>
<head>
<title><Smereka Func="GetWinTitle" /></title>
<link rel="StyleSheet" type="text/css"
href="{Smereka Func="GetHomeURL" /}files/main.css" />
</head>
<body>
<table>
 <tr>
 <td>
 <Smereka Method="Inspector" Display="Crown" />
 </td>
 <td>
 <h1>
 <Smereka Func="GetDocTitle" />
 </h1>
 <Smereka Method="CompiledAttr" />
 </td>
 </tr>
</table>
<Smereka Func="GetAttr" AttrName="AutonomText" NodeId="2048" />
</body>
</html>

Despite its simplicity, it is a fully functional template, which can be taken as basis for further development. Let's see how it works.

In the head section of page placed window title descriptor (<title>). The smeretag <Smereka Func="GetWinTitle" /> becomes its value. Since the NodeId parameter is not provided, during page compilation Smereka will call the GetWinTitle function and pass the current node (from which page is compiled) as parameter. This function in accordance with its name calculates the page title and return it as string, inserted in the resulting HTML document. By default, this function returns the WinTitle attribute on the node, but it can do more complex operations.

In describing the style sheet we see next smeretag {Smereka Func="GetHomeURL" /}. Because the rules of HTML prevent tags to be attribute values, it is taken not in broken brackets, but in curly. This function returns the home page URL, for example . In the most cases we know the name of the site, and can put its value instead smeretag, but if you had to move the site from test address to a working address, or have multiple versions of site for various purposes, which have different domain names, this elementary smeretag dramatically facilitates support for templates. It provides independence of template from specific domain name.

In the body we see the table in the left cell which is placed smeretag <Smereka Method="Inspector" Display="Crown" />. How does it calculate the result you can see on this page (what you are reading now). To generate a tree navigator of documents used such a smeretag with the following parameters.

Next smeretag <Smereka Func="GetDocTitle" /> calculates the page title to format it with top-level heading tag. By default, this function returns the DocTitle attribute of current node, and although it may do more complex calculations.

Next smeretag <Smereka Method="CompiledAttr" /> load HTMLCode attribute of current node and compiles it, that calculates smeretags that (maybe) contained in this code. Result of the calculation is the main source of the page (for example, the one you are reading now).

Fragments

Last smeretag in template <Smereka Func="GetAttr" AttrName="AutonomText" NodeId="2048" />. It produces AutonomText attribute not from current node, but from node with the id (for example) 2048. This autonomous text may contain, for example, counters code in your page (Google Analytics even recommend placing its meter before the end of page), or code offer of any advertising system or anything else.

Since the code is not dependent on the current node, it just like site URL can be inserted directly in the template. Placing it in a separate node (which by itself is not designed to generate web page) has the advantage that facilitates the tracking and development patterns.

This technique of insertion static blocks of code from some Smereka nodes referred as fragments technique. Fragments are easier job if the block of code must be inserted into a several templates and to ensure its identity. Then changed one piece (for example, adding a new meter) automatically modifies all pages that contain it.

Fragments may be language-dependent. To achieve this, the text fragments should be stored in language-dependent attribute, such as HTMLCode. This will ensure the translation of the fragment and page layout according to the language defined by the user. This technique allows to adapt the language of display ads in the main language of page, etc.

Using

When the template is created, you can debug and use it. To do this one have indicate the need to use it, that link it to some site metatemplate. Metatemplate can use the template text inserted into the database (recommended) or a from separate file (then path and file name will be specified).

Now some in our tree nodes can be associated with a newly created template and we can see how the generated pages look. After modifying the desired template can be transferred into operation.

Additional power for templates is provide by section, that allow create new templates of existing ones. This described in the next article.

Previous section | Table of content | Next section

Please this page? Help us to develop this site!

1978 2018 N.I.Zharkikh

Reprinting of articles from site are encouraged while
reference (hyperlink) to my site is provided

Site powered by

Load count : 1606

Modified : 8.08.2017

If you look up the type error
on this page, please select it
by mouse and press Ctrl+Enter.