Linked Questions

15
votes
3answers
29k 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....
9
votes
1answer
16k 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 ...
8
votes
3answers
9k 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' %} ...
6
votes
5answers
26k 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"...
3
votes
1answer
367 views

Hide/Show fields value in nodes

I have a content type = Article. There I have 2 field. What I want is, If field 1 is empty or does not contain any value, replace this field with field 2, (with same css and html structure) else keep ...
2
votes
2answers
1k 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?
2
votes
1answer
190 views

how to just print the value of author in node template

There are some variables like author_name in node.html.twig of Drupal 8. {{ author_name }} will print something like below: <div><span><span>Basic</span></span></div&...
2
votes
1answer
647 views

Show comment author e-mail in comment.html.twig

Anonymous users can leave their e-mail when posting a comment but how can I display this e-mail as a plain text value in the comment.html.twig?
1
vote
3answers
5k 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 ...
1
vote
3answers
460 views

Body Summary field showing literal ampersand character code in view

I have a Drupal 8 site where we've created a view, and decided to use the summary field instead of the trimmed body field, so that we could have more control over it. However, I got a bug report ...
1
vote
1answer
605 views

How to get the values from a formatted field in inc file

I have a description field with a CK editor enabled. And when I get the data from it as node->get('fieldname')->getString() it outputs the content as below. The contents that I have entered in ...
1
vote
1answer
262 views

how do I access raw URL from a File Field to render it in twig inside href? [duplicate]

I have a "Our Staff" Content Type, that includes a field for uploading an individual's CV as a PDF: field_cv_file I have created a View for this Content Type, then added it to page via Blocks The ...
1
vote
1answer
167 views

How can I embed a view in a template when passing view name and parameters are passed as variables?

Inside my paragraph template I have variables which contain category id and view machine name. So when I print them like this: {{ content.field_category }} {{ content.field_view }} I get correct ...
1
vote
1answer
2k 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 ...
0
votes
3answers
2k 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 ...

15 30 50 per page