djblets.features.templatetags.features¶
Template tags for working with features.
- class IfFeatureNode(nodelist_enabled, nodelist_disabled, feature_id, extra_kwargs)[source]¶
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.- 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
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
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 %}