I have added a header image field to most of my entities of my website so that the header image can be overwritten if needed. On any node, my code in my page.html.twig file works perfectly:
{% if node.field_header_image.entity.uri.value %}
<section class="hero d-flex" style="background-image: url({{ file_url(node.field_header_image.entity.uri.value) }})">
{% else %}
<section class="hero d-flex">
{% endif %}
However, I've added a field_header_image
field to my taxonomy terms and can't seem to find a way to get the code I need to print on my page.html.twig
file.
On my taxonomy page template file, if I print the following code:
{{ file_url(elements['#taxonomy_term'].field_header_image.entity.uri.value) }}
I get what I need but this doesn't work in page.html.twig file.
Any suggestions on how I can access this? Or is there another way for me to overwrite the header image on my taxonomy terms?
EDIT: Is there a way to do this through a preprocess?