Comparison of Drupal 8 and Drupal 7 printing variables

71

In this article, we will know to print variable in Twig file and PHPTemplate as we know Drupal 7 using PHPTemplate and Drupal 8 Using Twig file.

Printing a variable:

Drupal 7 >> PHPTemplate: <div class="content"><?php print $content; ?></div>
Drupal 8 >> Twig: <div class="content">{{ content }}</div>

Printing a hash key item[1]

Drupal 7 >> PHPTemplate: <?php print $item['#item']['alt']; ?>
Drupal 8 >> Twig: {{ item['#item'].alt }}

Assigning a variable:

Drupal 7 >> PHPTemplate: <?php $data = $content->comments; ?>
Drupal 8 >> Twig: {% set data = content.comments %}

Assigning an array:

Drupal 7 >> PHPTemplate: <?php $result = array('@name' => $name, '@email' => $email); ?>
Drupal 8 >> Twig: {% set result = {'@name': name, '@email': email} %}

LEAVE A REPLY

Please enter your comment!
Please enter your name here