Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Twig Template Basics Syntax in D8

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 570
    Comment on it

    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.

    for eg:

    {#
         <header id="header" class="header">
            <h1 class="logo"> {{ page.header }} </h1>
        </header>
    #}

     

    Debugging variables:
    dump() function is used to debugging variables. eg: {{ dump(page) }}

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: