Wednesday, 10 March 2010
Home | Gunther | mamgoo | Search & Rescue
Working With Templates

Working With Templates


The way that pages served by Gunther look is dictated by the current template. Gunther has a built-in template which it uses to display pages by default. This template looks nice but you will undoubtedly want to customise the way that your own Gunther-powered site looks. You can do this by creating user templates which are then listed on the Manage Website screen. You can then choose which user template to use to display pages (by default) and also choose specific templates for specific pages on your Gunther site.

Gunther Loves Smarty


Gunther uses the Smarty PHP template engine to process templates. Smarty is a powerful tool and many of its features can be taken advantage of from within Gunther. A good crash course in smarty is available online.

To build a working template, you need to know what variables Gunther passes to Smarty. The following list describes each variable that Gunther generates:

$web_root

The base URL of the Gunther installation. $web_root will always end with a forward-slash. For example:
http://www.mysite.com/gunther/

$page_title

The title of the page. Example usage:
<title>{$page_title}</title>

$page_body

The body of the page. Gunther processes the content of the page, adding the necessary HTML tags and assigns the resulting HTML to this variable.

$page_name

The name of the page as it appears in the list of pages on the Manage Website screen.

$last_mod_time

The time at which the page was last modified. The time is represented in $last_mod_time as a number and needs to be converted into a string when references within a template. This is done using the date_form smarty variable modifier. For example:
Last modified: {$last_mod_time|date_format:"%a, %e %B %Y (%r)"}
...within your template would result in a string such as Last modified: Mon, 22 March 2004 (08:24:32 PM) being produced.

$tpl_base_url

A URL which points to the directory on your Gunther site holding all template related uploads. When including images within a template they should be uploaded from the Edit Template screen and references like this:
<img src="{$tpl_base_url}my_image.gif" />

$is_admin

A boolean indicating whether or not the current user is logged in to Gunther as an administrator. You can use this with a Smarty if-else statement to change the way your page appears between admin users and non-admin visitors. An example, changing the background colour for admin users with CSS:
{if $is_admin}
body { background-color: #DDDDDD; }
{else}
body { background-color: #E4E4E4; }
{/if}

Embedding Pages Within Templates


You might want to permanently 'embed' a page within a template. For example, you might want to create a page with a list of links and embed it within your template at a button bar. Gunther provides some Smarty functions which can be used to do this. To embed a page you should use the gunther_include Smarty function:
{gunther_include page="ButtonBarPage"}

Gunther Smarty Functions


The following is a list of the Smarty functions that Gunther adds.

{gunther_include page="ExamplePageName"}

Processes and outputs the page specified in the page parameter. Used to embed the contents of a named page within a template.

{gunther_page_url page="ExamplePageName"}

Outputs the URL for viewing the page specified in the page parameter. For example http://www.mysite.com/view.php/page/ExamplePageName.

More to come...
  Last modified: Sat, 5 June 2004 (08:51:14 PM)