djblets.features.templatetags.features¶
Template tags for working with features.
- class IfFeatureNode(nodelist_enabled: NodeList, nodelist_disabled: NodeList, feature_id: FilterExpression, extra_kwargs: Dict)¶
Bases:
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 = ('nodelist_true', 'nodelist_false')¶
- __init__(nodelist_enabled: NodeList, nodelist_disabled: NodeList, feature_id: FilterExpression, extra_kwargs: Dict) → None¶
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 (
django.template.FilterExpression
) – The template filter expression containing the ID of the feature to check.extra_kwargs (
dict
) – Extra keyword arguments to pass toFeature.is_enabled()
.
- __repr__() → str¶
Return a representation of the node.
This is mostly used for debugging output.
- Returns:
A representation of this node.
- Return type:
- render(context: Context) → str¶
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:
- if_feature_enabled(parser: Parser, token: Token) → IfFeatureNode¶
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: Parser, token: Token) → IfFeatureNode¶
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 %}