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