Templates: Top Level Blocks
General notes
Each block begins with its definition and ends with special command end
.
'end' [ 'namespace' | 'class' | 'template' ]
This command may optionally include block type after it. For example:
<% namespace vary %> <% class master uses data %> ... <% end class %> <% end %>
So we closed namespace
without block type and class
with specification.
It may be used as additional checking of order of blocks.
namespace
<a name="Syntax:"></a>Syntax:
'namespace' (NAME|'vary')
It is topmost command in every template.
Namespace can be specified by specific name, or using vary
keyword that mean that its name should be defined
externally during build process using switch -n
.
Notes
- If all the skin you create would not share any part with other skin, specify its name, otherwise use
vary
. - You can't use both
vary
and predefined namespace withing same skin.
class
<a name="Syntax:"></a>Syntax:
'class' NAME 'uses' IDENTIFIER ['extends' NAME]
Creates new class that responsible on rendering specific type of content pages. 'uses' IDENTIFIER
specifies the type of the content that this class should render. It actually defines content
reference member of this type.
Remember this note, in some cases, you would have to access content
member directly.
You can specify 'extends' NAME
if you want that new created class would inherit from other template class.
Derivation restrictions
When you create derived class the content of the child should be derived from the content of its parent as well. For example:
<% class master uses data::master %> .. <% end class %> <% class page uses data::page extends master %> ... <% end class %>
Then, data::page
must be derived from data::master
.
Rationale:
When you create master
parent you need provide for it a content as well. It receives its child content, thus it
may work if its child content derived from its parent content.
Generated Code
The generated code for the above two examples would look like this (approximately):
class master : public base_view { data::master &content; master(settings s,data::master cnt) : base_view(settings), content(cnt) { ... } ... }; class page : public master { data::page &content; page(settings s,data::page cnt) : master(s,cnt), content(cnt) { ... } ... };
template
Syntax
Definition of template consists of its name, round brackets and optional, comma separated list of parameters:
'template' NAME '(' [ parameter [',' parameter ... ] ] ')'
Where parameters
is :
IDENTIFIER ['const' ] ['&'] NAME
For example:
<% template render() %> <% template show_list(data::list_t const &list) %> <% template show_numbers(int x,int y, double z) %>
Note: you can not specify template parameters like list<int>
. You should define a type for them.
Generated Code
Each template is translated to virtual member function of the class it defined in. This function
returns void
and receives defined parameters, thus, show_list
in the above example would be
translated to:
virtual void show_list(data::list_t const &list) { ... }