Skip to content

The template system

abidibo edited this page Jun 10, 2011 · 5 revisions

Jeff is a MVC framework. The final html is obtained parsing the templates. There are

  • global templetes (at theme level)
  • module templates (at module level)

The global templates are those which renders the whole document starting from <html> to </html>, they stays in the theme folder and are called by the template factory basing upon url request and user authentication. The module templates are used to render the modules' methods responses, and returns html blocks that will be inserted into the global template.

The global templates

Are files with the extension .tpl. Are written in html with some special tags parsed by the template engine. Special tags are rounded by {} parenthesis. Jeff supports only some tags by now, but they can be easily extended to perform more actions. In particular Jeff base has two kinds of special tags: ###Variable tags Are tags like {JAVASCRIPT} or {TITLE}. When the template engine parses the template file they are replaced by some values or functions. For example the tag {JAVASCRIPT} will be replaced with the inclusions of javascript files stored in the registry->js properties. The tag {TITLE} will be replaced with the value of the registry->title property, that is why it's possible to set the application title depending on the module called by url. This variables are parsed in the parseVariables method of the template class (called by the public method parse). ###Module's methods inclusion tags Are tags used to insert module methods generated content inside the template. For example:
{module:page method:view params:credits}
when the template is parsed this tag is replaced by what returns the view method of the page module passing it the parameter 'credits', it's possible to pass also more parameters in the same string separating them by a character and then implement the parameters separation in the method called. This tags are parsed in the parseModules method of the template class (called by the public method parse).

##The module templates Are templates written in php. They use the context variables passed by the view calling them. A module's method which produces an output assigns variables to labels using the view methods. This labels are the ones to use inside the template, and forms its context. Then when the template is parsed this labels are evaluated to the variables assigned.
The modules' templates are placed inside the
/themes/<theme_name>/view
folder.

##Template inheritance The global and module's templates are parts of the theme system. Both kinds of template stays inside theme folder. When the theme class or the view class searches for the template file, they try to find it inside the used theme directories, if they can't, they will search it in the default theme directory.
So when creating a new theme it is possible to customize all the application appearance or not, and if we don't want to do so, is not necessary to copy all the templates because the template engines fallbacks on default theme's templates.

Clone this wiki locally