Writing a dynamic template is as simple as to write a code which outputs a valid layout JSON string. See from layout JSON reference document how it is structured. When a Player requests content from a dynamic template it doesn't see what's in it, it only sees what's coming out from the template execution. Actually it's possible to take existing normal template, put that to a dynamic template as a string and just return it. There's no "dynamic" in that kind of template but Player don't know it.
Both the actual layout and layout JSON representation loosely follows three hierarchy levels. On a top level there is a layout itself and its basic parameters like name, size and theme. On a middle level there are widget containers(windows where widgets are placed) in their basic settings like dimensions, name, type. On a bottom level there are the actual visualization widget definitions.
Templates are installed under "<HQSERVER>/hq-engine/hq-server/webapps/ROOT/WEB-INF/wmvisualizerTemplates/dyn"
Basic Layout Model
Layout is executed by HQ Server and result is sent back to a browser. Format of the content sent to a browser is a string representation of a JSON object. Layout template itself should either return a plain String or an Object which translates itself back to correct String format through its toString() method. This is effectively just what happens if plain org.json.JSONObject is returned from the template instead of a String.
In below code example we're using a JsonGroovyBuilder which at the end of the template returns org.json.JSONObject from it:
Layout Bindins
Various utility classes and API is exposed to template scripts through a binding variables.
| Binding | Class |
|---|---|
| dutil | DynlayoutUtils |
| dobj | DynObjectCreator |
| dwin | DynWinUtils |
| dapi | DynResourceApi |
Working with Layout Settings
Layout needs its basic settings:
Working with Layout Containers
There are three different containers for widgets.
Multi and Single Containers
Single:
Multi:
Table Container
Table
Working with Visualization Widgets
Widgets: