Custom Template

This tutorial will walk you through the process of creating a new template for an application in ZOO.


Getting Started

All the templates are located in /media/zoo/applications/APPLICATION/templates/TEMPLATE/.

The templates meta data and the template parameters can be found in the template.xml file. The actual template files for the views are called item.php, category.php, frontpage.php, tag.php and alphaindex.php.

Most templates also have a folder called renderer. In here you will find the item layouts, which tell the item how to render itself. Click here to see how you create a new item layout. Also, the custom element renderer can be found here. Click here for a description on how to create a new element renderer for the template.

Have a look at existing templates to get an impression of the template's folder structure.


Getting Into Detail

Lets create a demo template.

Create this folder: media/zoo/applications/APPLICATION/templates/demo/.

Next we will create a template.xml file:

<?xml version="1.0" encoding="utf-8"?>
<template>

    <name>Demo</name>
    <version>2.0.0</version>
    <creationDate>April 2010</creationDate>
    <author>John Doe</author>

    <authorEmail>john @ doe.com</authorEmail>
    <authorUrl>www.johndoe.com</authorUrl>
    <copyright>YOUR COPYRIGHT DISCLAIMER</copyright>
    <license></license>

    <description>This is my demo template</description>
    <params group="category"></params>
    <params group="item">
    </params>

</template>

To learn about the parameters, click here.

After that, we create the template files for the views: item view - item.php, category view - category.php, frontpage view - frontpage.php, tag view - tag.php and alphaindex view - alphaindex.php.

Next you will have to write the template code itself. Each view will have a custom set of variables, already filled with values.

All Views

  • $this - This is the current View object.
  • $this->application - This is the current Application object.
  • $this->template - This is the Template object.
  • $this->params - This is the Params object, containing the site parameters.

item.php

  • $this->item- This is the Item object.
  • $this->renderer - This is the Renderer object, needed to render the item.

category.php

  • $this->category - This is the Category object.
  • $this->items - This is an array containing Item objects, that are published in this category.

frontpage.php

  • $this->category - This is the Category object, containing the root category.
  • $this->items - This is an array containing Item objects, that are published on the frontpage.

tag.php

  • $this->tag - This is the Tag object.
  • $this->items - This is an array containing Item objects, that are tagged with the selected tag.

alphaindex.php

  • $this->alpha_char - This is a string containing the selected alpha char.
  • $this->selected_categories - This is an array containing Category objects, containing the selected categories.
  • $this->items - This is an array containing selected Item objects.

These variables provide you with all the information, you need to output a nice template.

To render an item in item view, you may use the item renderer. The call would look something like this:

$this->renderer->render('item.full', array('view' => $this, 'item' => $this->item);

The first parameter for the render function is the layout. Click here to learn more about creating a new layout. The second parameter is an array containing arguments for the render function. We need to provide the view and the item.


Conclusion

This tutorial walked you through the process of creating a new template. As with everything, learn from what is already provided and build on that.

ZOO Documentation