home

Browse documentation

ezyVet Knowledge Center

Get access to documentation, training, and other high-quality resources.

Twig template variables: Variable types

Each Twig template variable shows a type of value (for example, a text, a date or a list). The type of value tells you how to use the variable in a template.

Twig code in a template

A Twig template has text and Twig code. Twig code uses two types of tags:
  • Between {{ and }}, enter a variable to show a value in the document (for example, {{ contact.FirstName }})
  • Between {% and %}, enter a Twig tag that controls the document (for example, an if statement or a for loop)

The name of a variable has two or more parts, with a dot between each part. The first part is the record (for example, contact). The next part is the data of the record (for example, FirstName).

For more information about the Twig tags, refer to the Twig documentation:

Variable types

Type of valueHow to use the variableExample

Text or number

Enter the variable between {{ and }}.

{{ contact.FirstName }}

Price or total

Use the moneyformat Twig filter. Some variables show the value in currency format. For these variables, you do not use a filter.

{{ invoice.Total|moneyformat }}

Date

Use the dateformat Twig filter. To show the date in a different format, use the date Twig filter.

{{ consult.ConsultDate|dateformat }}

{{ consult.ConsultDate|date("d/m/Y") }}

Condition (true or not true)

Put the variable in a Twig if statement. When you use the variable without an if statement, the variable shows 1 or no value.

{% if animal.IsDead %} … {% endif %}

Record

Add one more variable after the variable. After the dot, you can use all variables of that type of record.

{{ animal.Breed.Name }}

List of records or values

Put the variable in a Twig for loop. To show a list of text values with a comma between each value, use the join Twig filter.

{% for pet in contact.Animals %}{{ pet.Name }}{% endfor %}

{{ animal.Demeanours|join(", ") }}

Formatted content

Use the raw Twig filter. If you do not use the raw filter, the document shows the HTML tags as text.

{{ contact.PostalAddress.AddressHtml|raw }}

Find the type of a variable

The Function column of each variable tells you the type of value:
  • "True if" at the start of the description: the variable shows if a condition is true
  • "Shows a list": the variable shows a list of records or values
  • "Shows the … record", with a tip to add one more variable: the variable shows a record
  • A note about the moneyformat, dateformat or raw Twig filter: the variable shows a price, a date or formatted content

Each page of Twig template variables also has help sections for the types of value in that page (for example, "Variables that check a condition").