15. Templating

15.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.

15.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>

See also Chapter 14, Internationalization

15.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="" />

Generated URLs depend on what urlProvider has been set in the general client configuration file client.ini. See Section 4.2, “ client.ini for details about urlProvider.

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
    • generated URL (Miniproxy mode): r.php?t=css&r=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
    • generated URL (Miniproxy mode): r.php?t=css&pl=layers&r=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
    • generated URL (Miniproxy mode): r.php?t=css&pl=hello&r=toto.css
  • Projects
    • path: /projects/myproject/htdocs/css/toto.css
    • Smarty: {r type=css}toto.css{/r}
    • generated URL: myproject/css/toto.css
    • generated URL (Miniproxy mode): r.php?t=css&pr=myproject&r=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
    • generated URL (Miniproxy mode): r.php?t=css&pl=layers&pr=myproject&r=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
    • generated URL (Miniproxy mode): r.php?t=css&pl=hello&pr=myproject&r=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
    • generated URL (Miniproxy): r.php?t=css&pl=myplugin&pr=myproject&r=toto.css