Jump to >

This documentation covers Djblets 2.0. You can see the latest Djblets documentation or all other versions.

djblets.features.templatetags.features

Template tags for working with features.

class IfFeatureNode(nodelist_enabled, nodelist_disabled, feature_id, extra_kwargs)[source]

Bases: django.template.base.Node

Template node for feature-based if statements.

This works mostly like a standard {% if %} tag, checking whether the given feature is enabled and rendering the content between it and the else/end tags only if matching the desired state.

This supports a {% else %}, to allow rendering content if the feature does not match the desired state.

This is used by both the {% if_feature_enabled %} and {% if_feature_disabled %} tags.

child_nodelists = (u'nodelist_true', u'nodelist_false')[source]
__init__(nodelist_enabled, nodelist_disabled, feature_id, extra_kwargs)[source]

Initialize the template node.

Parameters:
  • nodelist_enabled (django.template.NodeList) – The nodelist to render if the feature is enabled.
  • nodelist_disabled (django.template.NodeList) – The nodelist to render if the feature is disabled.
  • feature_id (unicode) – The ID of the feature to check.
  • extra_kwargs (dict) – Extra keyword arguments to pass to Feature.is_enabled().
__repr__()[source]

Return a representation of the node.

This is mostly used for debugging output.

Returns:A representation of this node.
Return type:unicode
render(context)[source]

Render the node.

This will determine if the feature is enabled or disabled, and render the appropriate list of nodes to a string.

Parameters:context (django.template.Context) – The context provided by the template.
Returns:The rendered content as a string.
Return type:unicode
if_feature_enabled(parser, token)[source]

Render content only if a feature is enabled.

This works mostly like a standard {% if %} tag, checking if the given feature is enabled before rendering the content between it and the else or end tags.

This supports a {% else %}, to allow rendering alternative content if the feature is disabled instead.

It also accepts additional keyword arguments that can be passed to Feature.is_enabled().

Parameters:
  • parser (django.template.Parser) – The parser being used to parse this template tag.
  • token (django.template.Token) – The token representing this template tag.
Returns:

The feature checker node to use for the template.

Return type:

IfFeatureNode

Example

{% if_feature_enabled "my-feature" user=request.user %}
This will only render if the feature is enabled for the user.
{% else %}
This will only render if the feature is disabled for the user.
{% endif_feature_enabled %}
if_feature_disabled(parser, token)[source]

Render content only if a feature is disabled.

This works mostly like a standard {% if %} tag, checking if the given feature is disabled before rendering the content between it and the else or end tags.

This supports a {% else %}, to allow rendering alternative content if the feature is enabled instead.

It also accepts additional keyword arguments that can be passed to Feature.is_enabled().

Parameters:
  • parser (django.template.Parser) – The parser being used to parse this template tag.
  • token (django.template.Token) – The token representing this template tag.
Returns:

The feature checker node to use for the template.

Return type:

IfFeatureNode

Example

{% if_feature_disabled "my-feature" user=request.user %}
This will only render if the feature is disabled for the user.
{% else %}
This will only render if the feature is enabled for the user.
{% endif_feature_disabled %}