Timeline for Display paragraph field value in field.html.twig - Paragraphs module
Current License: CC BY-SA 4.0
18 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 14, 2023 at 7:05 | history | edited | 4uk4 | CC BY-SA 4.0 |
added 2 characters in body
|
Sep 14, 2023 at 6:57 | history | edited | 4uk4 | CC BY-SA 4.0 |
added 105 characters in body
|
Sep 14, 2023 at 6:47 | history | edited | 4uk4 | CC BY-SA 4.0 |
why instanceof
|
Sep 13, 2023 at 21:12 | comment | added | user111239 |
Last q. Can you recommend any good resources about coding preprocess functions for paragraphs. There's nothing on Drupal\paragraphs\ParagraphInterface or instanceof ParagraphInterface that I'm aware of. Wondering how beginners learn to code this stuff. Thanks
|
|
Sep 13, 2023 at 20:58 | comment | added | user111239 |
Weird $variables['child_type'] = $paragraph->getType(); doesn't display using {{ child_type }} and I also don't get any output for {{ paragraph }} . Wondering am I missing a module or if functionality is disabled.
|
|
Sep 13, 2023 at 20:05 | comment | added | user111239 | No child and parent is right in my logic :) I have another preprocess function that displays fine to paragraph.html.twig but it won't display on field.html.twig. U can see it at drupal.org/project/paragraphs/issues/2881460. Maybe it's something with the Barrio theme I use: drupal.org/project/bootstrap_barrio Thanks! | |
Sep 13, 2023 at 19:41 | comment | added | 4uk4 | Isn't child and parent not the other way? You better start debugging by putting more variables in the template as mentioned before. | |
Sep 13, 2023 at 18:58 | comment | added | user111239 |
My parent paragraph type is sidebar_button_repeater and child paragraph type is sidebar_button . I'm outputting 3 buttons. In your code do I switch out the child_type and parent_type for sidebar_button_repeater and sidebar_button resp? If I have done the above right and added your code to mysubtheme.theme file in Drupal, shouldn't adding {{ color }} in field.html.twig output my hexcode? I use a List (text) for field_background_color where a user picks a hexcode from a select dropdown. I'm very new to Drupal. Thanks
|
|
Sep 13, 2023 at 16:48 | review | Suggested edits | |||
Sep 13, 2023 at 17:48 | |||||
Sep 13, 2023 at 16:46 | comment | added | user111239 |
Thanks I will study that tonight. For now I have a dirty solution using item.entity.field_background_color.value which I will post in the q. I appreciate your help and patience. :)
|
|
Sep 13, 2023 at 15:39 | comment | added | 4uk4 |
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 ...
|
|
Sep 13, 2023 at 14:45 | comment | added | user111239 |
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?
|
|
Sep 13, 2023 at 13:52 | comment | added | user111239 |
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.
|
|
Sep 13, 2023 at 13:18 | history | edited | 4uk4 | CC BY-SA 4.0 |
add complete code example for parent
|
Sep 13, 2023 at 13:18 | comment | added | 4uk4 | I've added a complete code example for the parent paragraph. | |
Sep 13, 2023 at 13:10 | comment | added | user111239 |
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.
|
|
Sep 13, 2023 at 6:36 | history | edited | 4uk4 | CC BY-SA 4.0 |
parent paragraph
|
Sep 13, 2023 at 6:24 | history | answered | 4uk4 | CC BY-SA 4.0 |