djblets.features.templatetags.features¶
Template tags for working with features.
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.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()
.
Return a representation of the node.
This is mostly used for debugging output.
Returns: A representation of this node. Return type: unicode
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
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: 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 %}
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: 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 %}