In this recipe, we will create a {% parse %}
template tag, which will allow you to put template snippets in the database. This is valuable when you want to provide different content for authenticated and unauthenticated users, when you want to include a personalized salutation or you don't want to hardcode the media paths in the database.
As usual, we will start with the utils
app that should be installed and ready for custom template tags.
An advanced custom template tag consists of a function that parses the arguments that are passed to the tag and a Node
class that renders the output of the tag or modifies the template context. Perform the following steps to create them:
First, let's create the function parsing the arguments of the template tag, as follows:
# utils/templatetags/utility_tags.py # -*- coding: UTF-8 -*- from __future__ import unicode_literals from django import template register = template.Library...