Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (20 sloc) 923 Bytes

Template Syntax

Swig uses the same template syntax as Django Templates

  • {{ opens variable
  • }} closes the variable

  • {# opens a comment block

  • #} closes a comment block

  • {% opens the start of a logic tag

  • %} closes a logic tag


Used to print a variable to the template. If the variable is not in the context we don't get an error, rather an empty string. You can use dot notation to access object proerties or array memebers.

<p>First Name: {{ users.0.first_name }}</p>

Variables also are able to be transformed via filters.


Comment tags are simply ignored. Comments can't span multitple lines.

{# This is a comment #}


Logic tags are operational blocks that have internal logic on how the template should proceed. Read more about tags.

{% if something %}
    This will display if something is truthy.
{% endif %}
Jump to Line
Something went wrong with that request. Please try again.