almost 6 years ago
Hello Readers, This tutorial will guide you about 'How to use twig syntax in Drupal 8'. These basics of twig syntax will help you to understand:
1. How to print value
2. How to use it with control statement like if, else
3. How to comment the line in twig template.
Printing variables Use this syntax {{ }} to print a variable in twig. for eg:
//This syntax is used to print out the result of expression like {{ page.primary_menu }}
Control statements: Use curly braces with percentile like {% … %} for logic statement or assignment
for eg:
{% if page.footer1 %} <div> {{ page.primary_menu }} </div> {% else %} <div> {{ page.custom_menu }} </div> {% endif %}
Comments: Use this syntax # … #} to comment the lines or blocks.
{# <header id="header" class="header"> <h1 class="logo"> {{ page.header }} </h1> </header> #}
Debugging variables: dump() function is used to debugging variables. eg: {{ dump(page) }}
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)