Login

Tag "silent"

Snippet List

Silently-failing include tag

This is the `local_settings.py` trick extended to Django templates. Sometimes you need to insert some arbitrary code in the HTML of the production site for external service integration like uservoice, typekit, google analytics... You don't want to put this code into source control because some other sites using the same source code may not need it. So, add this template tag to your collection and do: {% try_to_include 'head.html' %} And leave `head.html` out of source control. Then when you need to include some code on your production site, just add the `head.html` template with the desired code to include. I usually have one included template in the header for extra `<head>` tags, and one in the footer for extra javascript. Node that the included template is rendered against the current context. If the template doesn't exist, an empty string is returned. Also see the [full blog post](http://bruno.im/2009/dec/07/silently-failing-include-tag-in-django/) about this tag.

  • templatetag
  • include
  • silent
Read More

1 snippet posted so far.