Main  /  Edit version 5  /  Edit version 6  /   /  Users Area

Difference "Templates: General Concepts (v 1.x)" ver. 5 versus ver. 6

Content:

<!--toc-->
## Basic Structure of CppCMS template file
When we build templates, we put their content in their own `skin`. Thus when we build any template we specify its skin name as first level command. Each skin is represented
by separate namespace at C++ level. So skin name is
actually C++ namespace name.
The second level is view (C++'s class). Each view withing its skin represents certain page that should be rendered.
Each skin should implement `render()` virtual member function, unless it is already implemented in its parent.
Each view represented by separate class that is derived
from `cppcms::base_view` at topmost parent.
Example:
<% skin purple %>
<% view master uses data::master %>
<% template render() %>
...
<% end template %>
<% end view %>
<% end skin %>
All views may be organized to inheritance hierarchy. For example, we can have following hierarchy for typical blog:
[master]
/ \
[page] [summary]
/ \ / \
[post] [info.] [archive] [recent_posts]
Where `master` defines general appearance of the page --- theme. `page` uses for displaying general page
in blog that can be `post` or `info` -- information page. On the other hand `summary` represents list of recent posts
or archive by category.
Each inherited view may redefine its parent templates that are actually virtual functions.
## Syntax
### HTML and Controls separation
Template system of CppCMS is bases on HTML pages with injected flow control commands between `<% %>` tags.
Each template command starts with `<%` and should be closed with `%>` in same line.
Each template command should be closed with these "brackets".
For example --- correct code:
<% if not empty Name %>
Hello <% Name %>
<% else %>
Hello Visitor
<% end %>
It is incorrect to "merge different commands. For example (incorrect):
Hello <% if not empty name ; name ; else %>Visitor<% end %>
You should not split command on different rows as well. The following is incorrect:
<% if not empty
name %> Not empty <% end %>
Symbols inside commands can not include `%` or `>`. You may include them inside double quotes using C++/C escaping
rules. For example:
<% number | intf("<%04x>") %>
### Syntax Description Rules
Describing syntax of template commands is done in following way:
- All keywords will be shown in small caps in single quotes. For example 'skin'
- **NAME** is sequence of Latin letters, digits and underscore starting with letter. They represent identifiers
and can be defined by regular expression as: `[a-zA-Z][a-zA-Z0-9_]*`. For example `skin_1`.
- **VARIABLE** is non-empty sequence of NAMES separated by dot "`.`" or "`->`" that may optionally end with `()` for identification of function call result. No blanks are allowed. For example: `data->point.x`, `something.else()`.
- **VARIABLE** is non-empty sequence of NAMES separated by dot "`.`" or "`->`" that may optionally end with `()` and begin with `*` for identification of function call result. No blanks are allowed. For example: `data->point.x`, `something.else()` `*foo.bar`.
- **STRING** is standard C++/C string with standard escape characters like `"Hello \"World\""`. _Note:_ No string concatenation is allowed like `"Hello " "World"` that is equivalent of `"Hello World"`.
- **NUMBER** is a number -- sequence of digits that may start with `-` and include `.`. It can be defined by regular expression: `\-?\d+(\.\d*)?`
- **IDENTIFIER** is a sequence of NAME separated with `::` symbol. No blanks are allowed. For example: `data::page`
- All punctuation symbols are enclosed with single quotes. Like `','`.
- Non-mandatory elements are displayed withing rectangular brackets `[]` and mandatory using round brackets `()`. Options are separated using `|` symbol.
- There is no limit on blanks between the words.
For example:
'view' NAME 'uses' IDENTIFIER ['extends' NAME]
Means that following definitions are legal:
<% view page uses data::page extends master %>
<% view test uses data::test %>
<% view test uses data_test %>
And these are not:
<% view 1page uses data::page extends master %>
<% view page %>
<% view page uses data::page extends other::master %>

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0