Templatelite Module¶
Exceptions¶
-
exception
templatelite.
UnknownContextValue
¶ Raised when a Context Variable does not exist. This is the dot separated version of the variable name
-
exception
templatelite.
UnrecognisedFilter
¶ Raised when a filter is invoked on a Context Variable, but the filter is not recognised.
-
exception
templatelite.
UnexpectedFilterArguments
¶ Raised when arguments are provided for a given filter, but where those arguments were not unexpected.
-
exception
templatelite.
TemplateSyntaxError
¶ Raised when the template does not meet the expected syntax - this will be caused by an missing or unexpected directive
Renderer Class¶
-
class
templatelite.
Renderer
(template_str=None, template_fp=None, template_file='', errors=False, default=None, remove_indentation=True)¶ A General purpose Template renderer
Parameters: - template_str – The Template to render
- errors – A Boolean flag - True if errors in the template should cause an exception
- default – The default value to insert into the template if an error occurs.
- remove_indentation – Whether or not to remove the left margin indentation.
By using the default values from the class, any data access error in a
ContextVariable
will cause that context Variable to be rendered into the template as the unconverted context variable name. Errors in accessing data within for loops or if conditions then the value of None is used.if
default
is set then this string is used under error conditions (rather than the context variable name)If
errors
is set then any error within the template will cause aUnknownContextValue
,UnrecognisedFilter
orUnexpectedFilterArguments
exception as appropriate.The
remove_indentation
flag will strip all left margin indentation from the template as it renders. This setting is suitable for templates where any indentation is inconsequential (e.g. html). If the template is intended to create output where indentation needs to be preserved (Restructured Text (.rst), Python Source Code (.py) thenremove_indentation
needs to set to false).-
classmethod
execute_filter
(filter_name='', token='', value=None, args=(), kwargs={})¶ Generic class method to execute a named filter
Run at execute time
-
from_context
(*contexts)¶ Public I/f Render the template based on one or more dictionaries
-
classmethod
register_filter
(name, filter_callable)¶ Register a named modifier - internal use only