Score:0

Menu item extras field in page.html.twig

cn flag

I need a background image per menu item. For this I'm using menu_item_extras. I added an image field to menu items. This field I'd like to use in page.html.twig.

How can I use this field in this template?

leymannx avatar
ne flag
Current menu item image as page background image. You probably should preprocess the page get the menu in there, get all menu items, compare with current URL, if match get the menu item's image field, load image, get image URL, pass image URL over to the template via `$variables['my_background_image']` and then in the `page.html.twig` build the markup with `style="background-image: {{ my_background_image }}`.
cn flag
It shouldn't be the page background ;-) Unfortunately, I don't know how to write this function at all. Can you help me there?
cn flag
I got it with a views block. I use a contextual filter for the menu link entity id and filter by active menu item id. It works as expected.
in flag
You should post your fix as an answer to your question.
Score:0
cn flag

I got it with a views block. I use a contextual filter for the menu link entity id and filter by active menu item id. It works as expected.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.