Previous Page Next Page

Reducing Code Using the with Tag

Another template tag that you will find useful is with. The with tag allows you to assign a complex variable name a simpler one. This is most helpful when you have to reference the object several times.

For example, consider the business.accounting.contact_info subobject. Referencing that object several times would take a lot of keystrokes. The following example shows how to use the with tag to reduce the code necessary to reference the object:

{% with business.accounting.contact_info as ci %}
Phone: {{ ci.phone }}
Email: {{ ci.email }}
Website: {{ci.URL }}
{% endwith %}

Previous Page Next Page