cement.ext.ext_jinja2

Cement jinja2 extension module.

Note This extension has an external dependency on jinja2. Cement explicitly does not include external dependencies for optional extensions.

  • In Cement >=3.0.8 you must include cement[jinja2] in your applications dependencies.

  • In Cement <3.0.8 you must include jinja2 in your applications dependencies.

class cement.ext.ext_jinja2.Jinja2OutputHandler(*args, **kw)[source]

Bases: OutputHandler

This class implements the OutputHandler interface. It provides text output from template and uses the Jinja2 Templating Language. Please see the developer documentation on Output Handling.

class Meta[source]

Bases: object

Handler meta-data.

_setup(app)[source]

Called during application initialization and must setup the handler object making it ready for the framework or the application to make further calls to it.

Parameters:

app (instance) – The application object.

render(data, template=None, **kw)[source]

Take a data dictionary and render it using the given template file. Additional keyword arguments are ignored.

Parameters:

data (dict) – The data dictionary to render.

Keyword Arguments:

template (str) – The path to the template, after the template_module or template_dirs prefix as defined in the application.

Returns:

The rendered template text

Return type:

str

class cement.ext.ext_jinja2.Jinja2TemplateHandler(*args, **kw)[source]

Bases: TemplateHandler

This class implements the Template Handler interface. It renders content as template, and supports copying entire source template directories using the Jinja2 Templating Language. Please see the developer documentation on Template Handling.

class Meta[source]

Bases: object

Handler meta-data.

load(*args, **kw)[source]

Loads a template file first from self.app._meta.template_dirs and secondly from self.app._meta.template_module. The template_dirs have presedence.

Parameters:

template_path (str) – The secondary path of the template after either template_module or template_dirs prefix (set via App.Meta)

Returns:

The content of the template (str), the type of template (str: directory, or module), and the path (str) of the directory or module)

Return type:

tuple

Raises:

cement.core.exc.FrameworkError – If the template does not exist in either the template_module or template_dirs.

render(content, data, *args, **kw)[source]

Render the given content as template with the data dictionary.

Parameters:
  • content (str) – The template content to render.

  • data (dict) – The data dictionary to render.

Returns:

The rendered template text

Return type:

str