templatetags Package

splangotags Module

class splango.templatetags.splangotags.ExperimentNode(exp_name, variants_str)[source]

Bases: django.template.base.Node

Template node for the {% experiment ... %} template tag.

This

render() returns an empty string (thus {% experiment "..." variants "...,...,..." %} renders nothing) but it must be called so that the experiment is recorded appropriately.

render(context)[source]

Declare the experiment and enroll a variant. Render nothing.

Parameters:context (django.template.context.Context) – template context
Returns:empty string
Return type:basestring
Raises:django.template.TemplateSyntaxError if 'request' is not in context, or if the former does not have an experiments manager.
class splango.templatetags.splangotags.HypNode(exp_name, exp_variant, node_list)[source]

Bases: django.template.base.Node

Template node for a {% hyp %} template tag.

This render() method of this class either returns an empty string or the inner nodes rendered.

render(context)[source]

Render the node list if exp_variant is the enrolled variant.

Parameters:context (django.template.context.Context) – template context
Returns:node_list rendered or an empty string
Return type:basestring
Raises:django.template.TemplateSyntaxError if the experiment named exp_name has not been declared yet
splango.templatetags.splangotags.experiment(parser, token)[source]

Return a ExperimentNode according to the contents of token.

Example::
{% experiment “signup_button” variants “red,blue” %}
Parameters:
  • parser – template parser object, not used
  • token (django.template.base.Token) – tag contents i.e. between {% `` and `` %}
Returns:

experiment node

Return type:

ExperimentNode

Raises:

django.template.TemplateSyntaxError if tag arguments in token are different than three

splango.templatetags.splangotags.hyp(parser, token)[source]

Return a HypNode according to the contents of token.

Example::
{% hyp “signup_button” “blue” %}
Parameters:
  • parser (django.template.base.Parser) – template parser object
  • token (django.template.base.Token) – tag contents i.e. between {% `` and `` %}
Returns:

experiment node

Return type:

ExperimentNode

Raises:

django.template.TemplateSyntaxError if tag arguments in token are different than two