Lightspeed Template Bootcamp Series (Lesson 4)

Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 654 moderator
edited May 2018 in Tips, Tricks & How-to’s
Lesson 4 - Twig

Twig and Template Engines

Template Engines are a logical choice for applications structured with a back-end that serves information to a browser from a database.
They enable the application to interact with that data and serve it in a structured format.

Since our templates generally serve the purpose of creating Forms, Receipts and Quotes in a browser, we need HTML to show this.

Template Languages enable us to do simple programmatic operations and logic to an otherwise static HTML document. This enables us to serve dynamic data, i.e. information that changes depending on the data provided to it.

Here is how we assign variables to data:

Instead of using “var”, “let or “const” (as we saw in Javascript), Twig uses {% set %}

The image below shows how to write conditionals

The conditional can be read as this:

If the value assigned to the fixedNumber is greater than the value assigned to the testNumber then output the HTML immediately below it. Otherwise output the HTML underneath the {% else %} then end the conditional ( {% endif %}).

If you want to find out more about Twig, you can read about it here:
To play around with Twig on your browser, use this tool:

Next Lesson

Previous Lesson

Post edited by Adrian Samuel on

Adrian Samuel

Software Developer

Lightspeed HQ

Sign In or Register to comment.