Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • Thanks for helping. I added your preprocess function. So specifically in field.html.twig type templates (e.g field--paragraph--sidebar-button-repeater.html.twig ). do I just add {{ color }} to return the color e.g. Color is {{ color }}? That didn't work for me unfortunately. Also $parent = $paragraph->getParentEntity(); doesn't work for me in field.html.twig. It just works in paragraph.html.twig type templates. This link may lead to a solution: drupal.stackexchange.com/questions/233977/…. Question edited. Commented Sep 13, 2023 at 13:10
  • I've added a complete code example for the parent paragraph. Commented Sep 13, 2023 at 13:18
  • Thanks again. I must be overlooking something stupid my end. It just won't output the value for {{ color }} in field.html.twig or in paragraph.html.twig for that matter. I'll study it harder my end. I must be missing some setting. I appreciate the help! Using Drupal 9.5.10 if that applies. Commented Sep 13, 2023 at 13:52
  • My specific version of field.html.twig file is field--paragraph--sidebar-button-repeater.html.twig and {{ item.content }} does natively output the parent field field_background_color value. The problem is how to capture that specific value so I can use it in a situation like: <div style="background: [output from field_background_color ];"> in field--paragraph--sidebar-button-repeater.html.twig. I was hoping some iteration of {{ item.content['#node'].field_background_color.value }} would achieve it. Can some parent parameter be added to capture the field value? Commented Sep 13, 2023 at 14:45
  • If you test my code take baby steps. The first code line gets the entity where the field is placed. If it is a paragraph, it gets you to the second line. Put the result of the third line in a variable $variables['child_type'] = $paragraph->getType() and output it in the field template {{ child_type }} and so on ... Commented Sep 13, 2023 at 15:39