Wiki

Clone wiki

django-snippet / Home

Django-Snippet

Django-snippet is a simple drop in django application to provide snippet blocks in your templates. Snippets are blocks or lines of text that can be modified using the django backend.

Installing

  • pip install django-snippet
  • add 'snippet' to your INSTALLED_APPS
  • python manage.py syncdb

Simply Put

Stick in {% snippet "snippet_name" %} in your template, and when that template gets loaded, the snippet is automatically registered in the backend.

Basic Usage

{% snippet "snippet_name" %}

This is the simplest type of snippet.

Providing Default Value

{% snippet "snippet_name" "my default value" %}

You can provide a default value for the snippet. This is the value that will be saved into the database if the snippet hasn't been registered (or has been deleted)

Longer Default Values

{% snippetblock "snippet_name"%}
<ul>
  <li><a>Item</a></li>
  <li><a>Item</a></li>
  <li><a>Item</a></li>
  <li><a>Item</a></li>
</ul>
{% endsnippetblock %}

If you have a longer block of text (say, a whole chunk of html) then you can use the snippetblock template tag instead.

Updated