Dynamic template snippets for Django.
Pull request Compare This branch is 32 commits ahead, 84 commits behind zerok:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
snippets Version info changed. Starting development of version 0.2. Oct 27, 2009
.gitignore .gitignore updated. Oct 28, 2009
LICENSE.txt Added and changed some info in files setup.py and README. Feb 4, 2009
MANIFEST.in Updated MANIFEST.in Jan 20, 2009
README.rst django-snippet is no longer supported! Jul 16, 2015
ez_setup.py Fixed a bug in setup.py. Oct 28, 2009
setup.py Merged changes. Oct 28, 2009



(django-snippets is no longer supported!)

django-snippets provides a templatetag acting as an {% include %}, that loads a template and renders it with the current context, but the template content comes from database.

django-snippets is a fork of django-flatblocks, and the main difference is that django-snippets render the content as a Django template.


Once you've created some instances of the snippets.models.Snippet model, you can load it it using the snippets templatetag-library:

{% load snippets ... %}


{% get_comment_list for entry as comment_list  %}
{% if comment_list %}
  <ol>{% include_snippet "comment_list" %}</ol>
{% endif %}

This way you can include a snippet with the name "comment_list". If you have the name of a snippet in a template variable, leave out the quotes.

comment_list will be rendered as a Django template. This mean that you can use {% for %}, {% if %} and others template tags.

This tag also accepts an optional argument where you can specify the number of seconds, the that snippet should be cached:

{% include_snippet "comment_list" 3600 %}

If you use a snippet that doesn't exist, ``include_snippet`` will insert the value of the SNIPPET_STRING_IF_INVALID setting, which is '' (the empty string) by default.


django-snippets is available free software under the New BSD license. See the file LICENSE.txt for more information.