public class Templates extends Object
In contrast to the web server and its handlers Velocity is used here as template engine. This is because these templates are easier to write as they don't need andy type information. as these templates are less frequently executed the lower performance does not matter. The language reference of velocity, which is one of the most commonly used language for templates can be found here: http://velocity.apache.org/engine/devel/vtl-reference-guide.html
The template sources are loaded via Resources.resolve(String)
. If no resolver is available or none of the
available ones can load the template, it is tried to load the template from the classpath.
Specific output types are generated by ContentHandler
implementations. Those are either picked by the file
name of the template, or by setting Generator.handler(String)
. So if a file ends with .pdf.vm it is
first evaluated by velocity (expecting to generate XHTML) and then rendered to a PDF by flying saucer.
Alternatively the handler type pdf-vm can be set to ensure that this handler is picked.
Modifier and Type | Field and Description |
---|---|
static sirius.kernel.health.Log |
LOG |
Constructor and Description |
---|
Templates() |
Modifier and Type | Method and Description |
---|---|
Map<String,Object> |
createGlobalContext()
Collects all global variables to be used when rendering templates or executing user scripts.
|
Map<String,Object> |
createGlobalSystemScriptingContext()
Collects all global variables to be used when executing system scripts.
|
Generator |
generator()
Creates a new generator which can be used to generate a template based output.
|
List<String> |
getExtensions(String key)
Returns a list of all extensions provided for the given key.
|
public Generator generator()
Generator
which can be used to generate outputpublic Map<String,Object> createGlobalContext()
public Map<String,Object> createGlobalSystemScriptingContext()
public List<String> getExtensions(String key)
This can be used to provide templates that contain sections which can be extended by other components. Think of a generic template containing a menu. Items can be added to this menu using this mechanism.
Internally the ExtendedSettings
framework is used. Therefore all extensions
for the key X have to be defined in content.extensions.X like this:
content.extensions { X { extension-a { priority = 110 template = "a.html" } extension-b { priority = 120 template = "b.html" } } }
To utilize these extensions in Rythm, use the includeExtensions("name") tag. For Velocity a macro with the same name is provided.
key
- the name of the list of content extensions to retrieveExtendedSettings
Copyright © 2018. All rights reserved.