How to use If condition in Twig File (Drupal 8) and PHPTemplate (Drupal 7)

60

In this article, we will know, How to use If condition in Twig File (Drupal 8) and PHPTemplate (Drupal 7).

Examples of some Conditionals statements:

Drupal 7  PHPTemplate: <?php if ($content->name): endif; ?>

Drupal 8 Twig: {% if content.name %} {% endif %}

Drupal 7 PHPTemplate: <?php if (!empty($content->name)): endif; ?>

Drupal 8 Twig: {% if content.name is not empty %} {% endif %}

Drupal 7 PHPTemplate: <?php if (isset($content->name)): endif; ?>

Drupal 8 Twig: {% if content.name is defined %} {% endif %}

Drupal 7 PHPTemplate: <?php if ($count > 0): endif; ?>

Drupal 8  Twig: {% if count > 0 %} {% endif %} 

LEAVE A REPLY

Please enter your comment!
Please enter your name here