27.3 Custom Template Tags
Template tags come in a variety of shapes and sizes. A template tag is separated from the rest of the markup by the {% %} delimiters and may create scope (like block or with) or may simply be a command (like load or url). Tags may take any number of arguments and keyword arguments and can either change control flow (like if or for) or print values.
In the next few sections, we build several template tags. In all cases, our tags will be simple commands (we will not build scope) and will always print values (rather than change flow of control).
To start, we build a template tag to display related blog posts. This allows us to greatly simplify our tag_detail.html and startup_detail.html webpages. We then see how to replace ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access