Login

Snippets by adurdin

Snippet List

Switch template tag

The `{% switch %}` tag compares a variable against one or more values in `{% case %}` tags, and outputs the contents of the matching block. An optional `{% else %}` tag sets off the default output if no matches could be found: {% switch result_count %} {% case 0 %} There are no search results. {% case 1 %} There is one search result. {% else %} Jackpot! Your search found {{ result_count }} results. {% endswitch %} Each `{% case %}` tag can take multiple values to compare the variable against: {% switch username %} {% case "Jim" "Bob" "Joe" %} Me old mate {{ username }}! How ya doin? {% else %} Hello {{ username }} {% endswitch %}

  • tag
  • templatetag
  • switch
Read More

IfValueTag

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: {% ifvalue company.contact.email as email %} <h3>Email address</h3> <a href='mailto:{{ email }}'>{{ email }}</a> {% endifvalue %} Instead of this: {% if company.contact.email %} <h3>Email address</h3> <a href='mailto:{{ company.contact.email }}'>{{ company.contact.email }}</a> {% endifvalue %} The tags ifvalue and ifnotvalue are provided by this snippet. If you don't specify `as somename`, then the variable's value will be assigned to the name "value".

  • tag
Read More

adurdin has posted 2 snippets.