<img alt="" src="https://secure.agile365enterprise.com/790157.png" style="display:none;">

Drupal8 Theming: Part 2

author
By Sanjay Rohila May 1, 2015
Drupal8 Theming: Part 2
Drupal8 Theming: Part 2



Other than these basic things, there is a new feature called Filters in templates.

Filters

Some of the frequently used filters are:

addClass:

We can add new class to an element as:

without:

Print whole variable except child element given as argument, so that we can use them later. Eg.  and use later as . This filter creates a copy of the renderable array and removes child elements by key specified through arguments passed to the filter. The copy can be printed without these elements and specific elements can be used later.

passthrough & placeholder:

To pass-through a variable (!) or use as a placeholder (%), the passthrough or placeholder filters are used.

Submitted on 

Striptags:

Striptags removes all HTML tags from the variable.

 

Clean_Class:

The clean_class filter prepares a string to be used as a valid HTML class name. When adding classes dynamically for any value, use clean_class.

clean_id:

The clean_id (same as clean_class) filter prepares a string to be used as a valid HTML ID.

safe_join:

The safe_join filter joins several strings together with a supplied separator.

 

Spaceless:

The  tag is helpful for removing all non-text whitespace between several tags and statements.

  

Compiled markup will be without extra indentation:

 

Debugging:

Here is a doc https://www.drupal.org/node/1906392 about how to enable debugging in Twig templates. We can also dump variables in Twig templates.

So, these are the things which are different in the new system (template files). There are lots of changes still going on. Some of these can be changed later, but most of them are freezed.

References:

 

Template Files: https://www.drupal.org/node/1918824

Debugging Twig: https://www.drupal.org/node/1906392

Twig Filters  : https://www.drupal.org/node/2357633

 

Here's the first article in this series: Drupal8 Theming: Part 1 

Subscribe to our newsletter