Main  /  Edit  /  History  /   /  Users Area

Templates: General Concepts (v 1.x)

Basic Structure of a CppCMS template file

When we build templates, we put their content into their own skin. Thus when we build any template, we specify its skin name as the first level command. Each skin is represented by a separate namespace at the C++ level. So the skin name is actually the C++ namespace name.

The second level is view (representing a C++ class). Each view within its skin represents certain pages that should be rendered. Each view should implement the virtual function render(), unless it is already implemented in its parent. Each view is represented by a separate class that is derived from cppcms::base_view by the 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 the following hierarchy for a typical blog application:

            [master]
          /         \
    [page]           [summary]
    /    \           /       \
[post] [info.] [archive] [recent_posts]

Where master defines the 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 a list of recent posts or the archive by category.

Each inherited view may redefine its parent templates that are actually virtual functions.

Syntax

HTML and Controls separation

The template system of CppCMS is based on HTML pages with injected flow control commands between <% %> tags. Each template command starts with <% and should be closed with %> on the 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

The description of the syntax of template commands is done in the following way:

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