Cement defines a Template Interface, as well as a default DummyTemplateHandler that implements the interface as a placeholder but does not actually do anything.
Cement often includes multiple handler implementations of an interface that may or may not have additional features or functionality than the interface requires. The documentation below only references usage based on the interface and default handler (not the full capabilities of an implementation).
The following options under App.Meta modify configuration handling:
Option
Description
template_handler
The handler that implements the template interface.
Working with Templates
The template handler can be used to render content in-line, as well as copy render source directories before copying them to their destination.
Example: Working with Templates
from cement import App
​
classMyApp(App):
classMeta:
label ='myapp'
extensions =['jinja2']
template_handler ='jinja2'
​
with MyApp()as app:
# create a data dictionary for templating
data ={
'foo':'bar'
}
​
# render content as template
app.template.render('Foo => {{ foo }}', data)
​
# render and copy a source directory
src ='/path/to/source/dir'
dst ='/path/to/destination/dir'
app.template.copy(src, dst, data)
When copying a source directory, both the file/directory path names themselves are rendered as templates as well as the contents of files.
Creating a Template Handler
All interfaces in Cement can be overridden with your own implementation. This can be done either by sub-classing TemplateHandler itself, or by sub-classing an existing extension's handlers in order to alter their functionality.