Django provides the {% include %} template tag that allows one template to render and include another template. However, in situations when an error is raised because the template to include does not exist, rendering will outright fail. In this recipe, we will create a {% try_to_include %} template tag that includes another template if it exists, and fails silently by rendering as an empty string otherwise.
Creating a template tag to include a template if it exists
Getting ready
We will start again with the utils app that is installed and ready for custom template tags.