Access to group object fields in page.html.twig

Created on 9 January 2025, 3 months ago

Hello.

Is it posible to get access to group object values (When I on group page) in page.html.twig template?

Problem/Motivation

Such functionality you need, for example, if you add custom image field for node or group, but you need to show this image before content of your "page type". For example "Hero area", before breadcrumbs, sidebar and main ... so you must change your page.html.twig structure. It's working for "node" variables, but not working for "group" variables.

In page.html.twig I can use "node" object variables (when I on node page /node/333), for example {{ node.some_custom_img_field.entity.uri.value }},

but I can't use in page.html.twig "group" object variables (When I on group page /group/12), for example {{ group.some_custom_img_field.entity.uri.value }}

I check group object via {{ dump(group) }} in page.html.twig and I have "0 null". But, if I do the same on group-full.html.twig - I have success with "group" object values.

I use $group = \Drupal::request()->attributes->get('group'); in theme_preprocess_page and theme_preprocess_html to add some classnames to body tag , using conditions with fields values via $group->get('field_name')->getValue() and I have a success with it.

But I have no success with using twig variables for group ({{ group.field...value }}) in page.html.twig ... but node variables ({{ node.field...value }}) is working fine.

It posible to resolve this problem? I need access to group values in page.html.twig file.

Thank you.

💬 Support request
Status

Active

Version

1.6

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024