How to comment codes in TWIG ?

Whenever we write codes we may need to comment some codes to avoid displaying and executing the line.we need two ways of commenting , they are single line commenting and multi line commenting.

Single line commenting

Single line commenting is used to comment a line of code .

Syntax

{# Commented code #}

Example

{#   <h3>{{ heading_title }}</h3>   #}

Multi line commenting

Multi line commenting is used to comment a part of codes or multiple lines of codes. the syntax and way of commenting is same as of single line commenting for the multi line commenting.

Syntax

{# Commented code #}

Example

{#

{% if product %}
<span>{{ product.title }}</span>
{% endif %}

#}

Leave a Reply