diff --git a/dev/concepts/advanced/template_tags/index.html b/dev/concepts/advanced/template_tags/index.html index 9f590895..31ccb907 100644 --- a/dev/concepts/advanced/template_tags/index.html +++ b/dev/concepts/advanced/template_tags/index.html @@ -23,7 +23,7 @@ {# or with flags #} {% mytag name="John" required %} {% endmytag %} -
The @template_tag
decorator accepts the following parameters:
library
: The Django template library to register the tag withtag
: The name of the template tag (e.g. "mytag"
for {% mytag %}
)end_tag
: Optional. The name of the end tag (e.g. "endmytag"
for {% endmytag %}
)allowed_flags
: Optional. List of flags that can be used with the tag (e.g. ["required"]
for {% mytag required %}
)The function decorated with @template_tag
must accept at least two arguments:
node
: The node instance (we'll explain this in detail in the next section)context
: The Django template contextAny additional parameters in your function's signature define what inputs your template tag accepts. For example:
The @template_tag
decorator accepts the following parameters:
library
: The Django template library to register the tag withtag
: The name of the template tag (e.g. "mytag"
for {% mytag %}
)end_tag
: Optional. The name of the end tag (e.g. "endmytag"
for {% endmytag %}
)allowed_flags
: Optional. List of flags that can be used with the tag (e.g. ["required"]
for {% mytag required %}
)The function decorated with @template_tag
must accept at least two arguments:
node
: The node instance (we'll explain this in detail in the next section)context
: The Django template contextAny additional parameters in your function's signature define what inputs your template tag accepts. For example:
@template_tag(library, tag="greet")
def greet(
node: BaseNode,
context: Context,
@@ -73,7 +73,7 @@
# Register the node
GreetNode.register(library)
-
When using BaseNode
, you have access to several useful properties:
node_id
: A unique identifier for this node instanceflags
: Dictionary of flag values (e.g. {"required": True}
)params
: List of raw parameters passed to the tagnodelist
: The template nodes between the start and end tagsactive_flags
: List of flags that are currently set to TrueThis is what the node
parameter in the @template_tag
decorator gives you access to - it's the instance of the node class that was automatically created for your template tag.
When your tag has an end tag, you can access and render the content between the tags using nodelist
:
When using BaseNode
, you have access to several useful properties:
node_id
: A unique identifier for this node instanceflags
: Dictionary of flag values (e.g. {"required": True}
)params
: List of raw parameters passed to the tagnodelist
: The template nodes between the start and end tagscontents
: The raw contents between the start and end tagsactive_flags
: List of flags that are currently set to TrueThis is what the node
parameter in the @template_tag
decorator gives you access to - it's the instance of the node class that was automatically created for your template tag.
When your tag has an end tag, you can access and render the content between the tags using nodelist
:
class WrapNode(BaseNode):
tag = "wrap"
end_tag = "endwrap"
@@ -88,4 +88,4 @@
Hello, world!
{% endwrap %}
You can unregister a node from a library using the unregister
method:
This is particularly useful in testing when you want to clean up after registering temporary tags.