Browse cities

Drupal development is becoming an increasingly popular choice for developers all around the world. This has sparked the interest for upgrades for this technology. Drupal used to work with the PHPTemplate engine which sought to separate the presentation layer from the logic layer. Recently Drupal development took one step further by replacing PHPTemplate with Twig, the latter being more secure and powerful.

 

Twig & Drupal Development

With Drupal 7, text previously submitted by the user needed the check_plain() function in order to prevent the ever-present vulnerability of cross site scripting or XSS.

If a theme’s output wasn’t sanitized, it was a huge security risk. Autoescaping was recently accepted into Drupal 8 as well, which made Drupal development much safer.

PHP functions are also removed from templates, in line with separation of concerns. Here is the new Drupal development mark-up:

Old: <?php print render($content); ?>

 

New: {{ content }}

The new syntax makes Drupal development faster and cleaner, a clear separation between presentation and logic with an added security boost. Twig offers many other benefits including that of inheritance – this has been called one of Twig’s biggest assets.

 

By integrating Drupal development with Twig, the need to copy and paste the parent theme template files into custom templates is eliminated. Twig limits the amount of template code and files you need to organize within your theme.

{% extends "themes/sub_bartik/templates/node.html.twig" %}

This is quite similar to PHP’s „include function” – it allows you to create hookable, dynamic templates. But there’s another feature which makes Twig great: Twig blocks

Parent file:

{# This empty block allows child templates to insert markup into this place in the header without re-writing the entire template. #} {% block header_fields %} {% endblock %}
New file:

{# Override the header_fields block to put field_image there because this site needs it there. #} {% block header_fields %} {{ content.field_image }} {% endblock %}
 

With the use of Twig and Twig blocks, Drupal development will become much easier – this also makes Drupal websites much safer and powerful.

Development

We do Drupal development

Go to our Drupal page!

Visit page!

Recommended Stories

Acquia DAM: What Is It? And How Precisely Does It Streamline Your Content Production Process?
PDFs, infographics, icons, logos, fonts, videos... How complex is your "ecosystem" of creative digital assets? And… (Read more)
Adriana Cacoveanu / Dec 6 '2019
Why We Fired Capex CPA and Why You Should Think Twice Before Putting Your Accounts into Their Hands
"Our goal is to have you relax and know that your tax and regulatory compliance are on cruise control." Just mind… (Read more)
Adrian Ababei / Dec 4 '2019
Automatic Updates in Drupal: From Mission Impossible to... Drupal’s New Auto Update Feature. How Does It Work?
The waiting is over. We'll have automatic updates in Drupal sooner than we even dared to hope.   Source: Drupal… (Read more)
Adriana Cacoveanu / Nov 29 '2019