Custom List Template

Each of the common components used in workflows of the Istarel Workshop Application Framework have default templates for rendering. They take a common sense approach to how each component (like a list or form) should be displayed. However, there are many cases where the default template does not quite meet the needs of a particular application module.

For example, suppose you want the commands for a list to appear both above and below the list itself (this can be useful when you know the list will be a long one). The default template only puts the commands after the list. There are two parts to changing the template.

  • Create a DefaultListTemplate subcless: technically, you can create any class that conforms to the ListTemplateProtocol interface, but for this example, a subclass is much simpler
  • Let the framework know about the custom template in the applicable application module

Listing: CategoryListTemplate.php

class CategoryListTemplate extends DefaultListTemplate
{
    function listTemplate()
    {
        $xml  = "\n<!-- LIST BEGINS -->\n\n";

        $xml .= "{*commands*}\n";
        $xml .= "<table{*attributes*}>\n";
        $xml .= "{*header*}";
        $xml .= "{*list*}";
        $xml .= "</table>\n";
        $xml .= "{*commands*}";

        $xml .= "\n<!-- LIST ENDS -->\n";

        return $xml;
    }
}

Notice the {*command*}s both above and below the list. That ensures that when the list is rendered, the commands (usually just "Add") will be both above and below the actual list. To notify the framework to use this template instead of the default, simply implement the listTemplateClass() method in the applicable application module.

Partial Listing: CategoryEditor.php

class CategoryEditor extends ApplicationEditor
{
    ...

    function listTemplateClass() { return 'CategoryListTemplate'; }

    ...
}

Now your application module renders its list the way you want!