Main  /  Edit  /  History  /   /  Users Area

Templates: General Concepts

Basic Structure of CppCMS template file

When we build templates, we put their content in their own namespace. Each namespace corresponds to separate skin. Thus when we build any template we specify its namespace as first level command.

The second level is class. Each class withing this namespace represents certain page that should be rendered. Each class should implement render() virtual member function, unless it is already implemented in its parent.


<% namespace skin1 %>
  <% class master uses data::master %>
    <% template render() %>
    <% end template %>
  <% end class %>
<% end namespace %>

All classes may be organized to inheritance hierarchy. For example, we can have following hierarchy for typical blog:

          /         \
    [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 class may redefine its parent templates that are actually virtual functions.


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:


CppCMS is a web development framework for performance demanding applications.

Support This Project Logo

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

CppCMS needs You


Main Page

Valid CSS | Valid XHTML 1.0