Template FunctionsΒΆ

Template functions return data which can be used inside a template.

Wishbone makes use of Jinja2 for all its templates. Template functions are functions which can be executed inside templates in order to render data.

Note

When bootstrapping a server the following template functions are always available:

  • strftime (wishbone.function.template.strftime)
  • epoch (wishbone.function.template.epoch)
  • env (wishbone.function.template.environment)
  • version (wishbone.function.template.)

Characteristics:

  • Template functions are functions which are added to the Jinja2 list of global functions.
  • Template functions are classes which base wishbone.function.template.TemplateFunction.
  • Template functions must have a get() method which provides the desired data.

Wishbone comes by default with following builtin template functions:

Name Description
wishbone.function.template.choice Returns a random element from the provided array.
wishbone.function.template.cycle Cycles through the provided array returning the next element.
wishbone.function.template.environment Returns environment variables.
wishbone.function.template.epoch Returns epoch with sub second accuracy as a float.
wishbone.function.template.pid Returns the PID of the current process.
wishbone.function.template.random_bool Randomly returns True or False
wishbone.function.template.random_integer Returns a random integer.
wishbone.function.template.random_uuid Returns a uuid value.
wishbone.function.template.random_word Returns a random word.
wishbone.function.template.regex Regex matching on a string.
wishbone.function.template.strftime Returns a formatted version of an epoch timestamp.
wishbone.function.template.version Returns the version of the desired module.

See following examples: