0

How to use twig expression in Drupal 8 content field and render. If I embed following twig expression in field value

{% if variable == 1 %} 
   you are logged in
{% endif %} 

When I render the field template I want to print "you are logged in".

Right now it renders as:

{% if variable == 1 %} 
  you are logged in
{% endif %} 

Though views allow Twig expression. Can we achieve same in content fields?

2 Answers 2

0

You cannot use Twig code as field value. You have to put that code in a template file. Or you can use Twig code in Views field value rewriting (but not as field value). 2nd is limited to variables of the view that are before to rewritten field. The function can be found in Views UI by clicking on the field name in the "Fields" section.

0

I think you can do that if you try to install this module https://www.drupal.org/project/twig_field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.