July 2017
Intermediate to advanced
456 pages
11h 32m
English
We are familiar with HTML commenting such as <!-- This is a comment -->, which allows us to add descriptive text to our markup. We saw an example of this in the Twig debug output once we enabled it. Twig provides us with the ability to add comments as well using the {# comment #} syntax.
If we open page.html.twig within our editor, we can add a Twig comment by adding the following:
{# This is a comment in Twig #} <h1>Welcome to Twig!</h1>
Once we save our template, refresh the browser and inspect the heading. We will note that we don't see the comment being displayed. Unlike HTML comments, Twig comments are meant to be hidden from browser output and are meant only for the developer.
Read now
Unlock full access