< Internationalization

Accounting  >

18. Templating

18.1. Introduction

Smarty Template Engine is a convenient way to write HTML templates for dynamic pages. It enables to delocalize a great amount of layout processing. Thus it is pretty easy to customize a CartoWeb application layout without affecting the application core.

CartoWeb templates are located in templates/ root directory and in plugins templates/ directories (see Section 2.3, “Plugins”).

More info about Smarty templates can be found here: http://smarty.php.net. A comprehensive online documentation including a reference and examples is available in various languages here: http://smarty.php.net/docs.php.

18.2. Internationalization

It is possible - and recommended! - to use the SmartyGettext tool in order to translate template-embedded textual strings. Texts to be translated are identified using the {t} tag:

<p>{t}Default text, please translate me{/t}</p>
<p>{t name="John Doe"}Hello my name is %1{/t}</p>
<p>{t 1='one' 2='two' 3='three'}The 1st parameter is %1, the 2nd is %2 and the 3nd %3.{/t}</p>

It is also possible to use the "|tr" smarty modifier if you want to apply some Smarty transformations on a translated string:

{assign var="label" value="Themes"}
<div {if $label|tr|count_characters:true < 10}style="width:72px;"{/if}>{$label|tr}</div>

See also Chapter 17, Internationalization

18.3. Resources

Resources are identified using the {r} tag. {r} tags have a mandatory type attribute and an optional plugin one. First attribute is used to indicate the relative file location (files are grouped by types) in the file system whereas the second one tells what plugin uses the resource. Filename is placed between opening and closing tags.

For instance to get the logo.png file located in htdocs/gfx/layout/, type in your template:

<img src="{r type=gfx/layout}logo.png{/r}" alt="" />

To get the zoom-in icons from the location plugin, type:

<img src="{r type=gfx plugin=location}zoom_in.gif{/r}" alt="" />

Following list shows all CartoWeb resource types.

  • Htdocs root directory
    • path: /htdocs/css/toto.css
    • Smarty: {r type=css}toto.css{/r}
    • generated URL: css/toto.css
  • Coreplugins
    • path: /coreplugins/layers/htdocs/css/toto.css
    • Smarty: {r type=css plugin=layers}toto.css{/r}
    • generated URL: layers/css/toto.css
  • Plugins
    • path: /plugins/hello/htdocs/css/toto.css
    • Smarty: {r type=css plugin=hello}toto.css{/r}
    • generated URL: hello/css/toto.css
  • Projects
    • path: /projects/myproject/htdocs/css/toto.css
    • Smarty: {r type=css}toto.css{/r}
    • generated URL: myproject/css/toto.css
  • Projects Coreplugins (override)
    • path: /projects/myproject/coreplugins/layers/htdocs/css/toto.css
    • Smarty: {r type=css plugin=layers}toto.css{/r}
    • generated URL: myproject/layers/css/toto.css
  • Projects Plugins (override)
    • path: /projects/myproject/plugins/hello/htdocs/css/toto.css
    • Smarty: {r type=css plugin=hello}toto.css{/r}
    • generated URL: myproject/hello/css/toto.css
  • Projects specific plugins
    • path: /projects/myproject/plugins/myplugin/htdocs/css/toto.css
    • Smarty: {r type=css plugin=myplugin}toto.css{/r}
    • generated URL: myproject/myplugin/css/toto.css
valid xhtml 1.0 valid css