Usage from Velocity Templates

The plugin automatically makes available the Tiles2Tool object under the tiles attribute for use within Velocity template. Here is the list of commands you can invoke in it:

  • getAsString(String attributeName) - get the value of named attribute as string.
  • importAttribute(String attributeName, String toName) - import the named attribute into the scope of template context under the (optional) custom name.
  • insertAttribute(String attributeName) - inserts given attribute in the output in its own context. If this is a string a string is printed, if this is a definition - it is included in the output.
  • insertAttribute(String attributeName, boolean ownContext) - inserts given attribute in the output. If this is a string a string is printed, if this is a definition - it is included in the output. You can specify whether a separate context is created for rendering the definition - in this case variables with duplicate names will not be inherited from the parent definition
  • insertDefinition(String definitionName) - renders a definition in its own context.
  • insertDefinition(String definitionName, boolean ownContext) - inserts definition, optionally in the shared context.
  • insertTemplate(String template) - inserts a named page, equivalent to Velocity's #parse.

    Here is a small example of the page using the tiles tool:

    <html>
            <head>
               <title>$tiles.getAsString("title")</title>   
            </head>
            <body>
                    <table border="1">
                            <tr>
                                    <td>
                                            $tiles.insertDefinition("left")
                                    </td>
                                    <td>
                                            $tiles.insertAttribute("center")
                                    </td>
                                    <td>
                                            $tiles.insertAttribute("right")
                                    </td>
                            </tr>
                            <tr>
                                    <td colspan="3">
                                            $tiles.insertDefinition("bottom")
                                    </td>
                            </tr>
                    </table>
            </body>
    </html>