Comparison Filters in Twig File and PHPTemplate

74

In this article, we will know – how to use Filters in Twig File  and PHPTemplate.

Filters

Translate:

Drupal 7 >> PHPTemplate:<?php print t('Home'); ?>
Drupal 8 >> Twig: {{ 'Home'|t }}

Escaped HTML special characters:

Drupal 7 >> PHPTemplate: <?php print check_plain($title); ?>
Drupal 8 >> Twig[2]: {{ title }}

Raw values:

Drupal 7 >> PHPTemplate: <?php print $title; ?>
Drupal 8 >> Twig: {{ title|raw }}

Implode a list:

Drupal 7 >> PHPTemplate: <?php echo implode(', ', $names); ?>
Drupal 8 >> Twig: {{ names | join(', ') }}

LEAVE A REPLY

Please enter your comment!
Please enter your name here