liveBook · Manning

Custom template tag

As explained in Django in Action

A custom template tag is an application-defined template instruction that performs an operation during template rendering.

A custom template tag is an application-defined template instruction that performs an operation during template rendering. Django treats tags as pluggable components, so templates can gain behavior beyond the built-in vocabulary. section 14.1

Use one when a repeated presentation task belongs in the template layer. Django provides shortcut mechanisms for some tag types, allowing small custom tags without building a large extension. section 14.1

Inline conditional output

The Django Awl library includes {% qif %}, an inline-if tag for conditional content when a full template block would take too much space. section 14.1

How Django in Action covers it

How deep it goes
Defines custom tags and mentions shortcuts, but defers implementation details to Django documentation and further guidance.
Examples
Uses the Django Awl {% qif %} tag as an inline conditional for compact template code.
What you can do after
Build it from scratch using Django’s custom-tag mechanisms and shortcut patterns.
How it connects
Connects custom template tags with template filters and Django’s pluggable component model.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.