0

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?

4
  • 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 }}.
    – leymannx
    Oct 11, 2021 at 12:37
  • It shouldn't be the page background ;-) Unfortunately, I don't know how to write this function at all. Can you help me there?
    – deelite
    Oct 11, 2021 at 15:45
  • 1
    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.
    – deelite
    Oct 11, 2021 at 16:19
  • You should post your fix as an answer to your question.
    – Beau
    Oct 12, 2021 at 21:38

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.