djangosnippets.org: Latest snippets posted by adurdinhttp://djangosnippets.org/users/adurdin/2008-08-13T05:25:24.696946-05:00adurdinSwitch template tag
2008-08-13T05:25:24.696946-05:00adurdinhttp://djangosnippets.org/snippets/967/<p>The <code>{% switch %}</code> tag compares a variable against one or more values in
<code>{% case %}</code> tags, and outputs the contents of the matching block. An
optional <code>{% else %}</code> tag sets off the default output if no matches
could be found:</p>
<pre><code>{% switch result_count %}
{% case 0 …</code></pre>
Freely redistributableIfValueTag
2007-03-22T07:15:30.510174-05:00adurdinhttp://djangosnippets.org/snippets/124/<p>Don't repeat yourself: when you wish to have a block of html with a variable value, but only if the variable is set, you can do this:</p>
<pre><code>{% ifvalue company.contact.email as email %}
<h3>Email address</h3>
<a href='mailto:{{ email }}'>{{ email }}</a>
{% endifvalue %}
</code></pre>
<p>Instead of this:</p>
<pre><code>{% if company.contact.email …</code></pre>
Freely redistributable