Django has the {% include %}
template tag that renders and includes another template. However, there is a problem in some situations, where an error is raised if the template does not exist. In this recipe, we will see how to create a {% try_to_include %}
template tag that includes another template and fails silently if there is no such template.
Advanced custom template tags consist of two things: the function that is parsing the arguments of the template tag and the Node
class that is responsible for the logic of the template tag as well as the output. Perform the following steps to create the {% try_to_include %}
template tag:
First, let's create the function parsing the template-tag arguments, as follows:
# utils/templatetags/utility_tags.py # -*- coding: UTF-8 -*- from __future__ import unicode_literals from...