Linked Questions

1 vote
3 answers
7k views

How to get value from {{ item.content }} [duplicate]

I have a node named "reviews" and a custom field named "field_rating". I created a field template named field--node--field_rating--reviews.html.twig. I want inside the node to change the color with ...
Pantaleão Cydon's user avatar
0 votes
1 answer
233 views

Twig Template - Div Element Being Inserted in Link URL [duplicate]

I have a link field type that I'm referencing in a Twig template. I'm using this code: <div class="outlined"> <a href="{{content.field_3_column_image_link}}">{{content....
Bryan Green's user avatar
-1 votes
1 answer
121 views

How to use a Twig variable as View name in drupal_view() Twig Tweaks function? [duplicate]

This works: {{ drupal_view('nursing_resource_blog_teasers', 'block_1') } But this doesn't: {% set view_name = "nursing_resource_blog_teasers" %} {{ drupal_view(view_name , 'block_1') } It ...
quantumized's user avatar
  • 1,227
15 votes
3 answers
30k views

How do I access field data in Twig?

I have a list field for a custom block type that looks like this: left|Align left right|Align right I can access the key in Twig by doing something like this: {% block content %} {{ content....
estrar's user avatar
  • 415
8 votes
8 answers
43k views

How do I convert special characters into html in twig

I have some list items in drupal 8 which created by item_list template.I am sending some <a> tagged data to the item_list template. My idea was to get the output as <a href="/this-is-new.html"...
i am batman's user avatar
9 votes
3 answers
11k views

How to test for a boolean field in a twig template?

field_boolean is a boolean field. {% if content.field_boolean == true %} or {% if content.field_boolean == 1 %} or {% if content.field_boolean == 'true' %} or {% if content.field_boolean == '1' %} ...
Pim's user avatar
  • 1,055
9 votes
1 answer
18k views

How can you render fields from an entity reference in node templates? [Drupal 8]

For context, I'm dealing with two content types: article and team_profile. In article nodes, we have an entity reference field pulling a team_profile node in to serve as the author information. I ...
alexbea's user avatar
  • 203
0 votes
1 answer
8k views

How to get field value from paragraph entity in twig?

Is it possible to get the value from the field inside the paragraph in the red rectangle. This code part is placed within a twig-template "field--block-content--field-example.html.twig" {% ...
Lance's user avatar
  • 313
0 votes
3 answers
3k views

twig if Term ID is something, then do something

I have a taxonomy called Fish and 2 terms in it. Bass and Gold. I have a term reference field on a Page node, and its a select list. The editor can select either Bass or Gold. And I want display ...
paul cappucci's user avatar
3 votes
2 answers
2k views

How to show/hide the prefix/suffix for fields?

Sometimes in theming I want to programmatically hide the prefix or suffix of numeric fields. How can I do so?
Mojtaba Reyhani's user avatar
0 votes
1 answer
4k views

How do I calculate field_1 + field_2 in Twig?

I have two fields. {{ content.field_1 }} is 2; {{ content.field_2 }} is 5. How do I multiply them to obtain 10, in a template file?
Oleksandr Osheko's user avatar
1 vote
1 answer
2k views

Check if a field is empty inside a twig paragraph template

I know how to check if a field is empty in a twig template (example node--lorem.html.twig): {% if node.field_lorem.value is not empty %} <p>not empty</p> {% else %} <p>...
Sébastien Gicquel's user avatar
0 votes
1 answer
2k views

Call preprocess_node (or get variables) from Twig template?

I have the following content types (for a simple LMS) defined: Lessons, for which there are rather complex rules for handling view access. Courses, which contain entity references to one or more ...
Marcus C.'s user avatar
  • 289
0 votes
1 answer
2k views

Twig escapes tags when using raw value in template

I am printing fields in a node template, but Twig is escaping my tags and ruining my day. My .tpl looks like this: <blockquote> <p class="title">{{ content.field_myfield.0 }}</p&...
Patrick Kenny's user avatar
3 votes
1 answer
3k views

How to add condition for 1st Iteration in views-view-fields.html.twig file

I am trying to implement a carousel , inside my views-view-fields--block_1.html.twig , I want to add active class inside the div for the first Iteration . I have added the code in twig file but every ...
Debasish's user avatar

15 30 50 per page