2

How can I print a user uploaded logo (via the theme appearance UI) in a twig template?

For example, in block--system-branding-block.html.twig we can use

Available variables:
- site_logo: Logo for site as defined in Appearance or theme settings.

  <img src="{{ site_logo }}" alt="{{ 'Home'|t }}" />

What do I need to do to make that variable (or a custom variable) available to another twig template, like menu.html.twig?

I have found many solutions, but all them involved hardcoding the logo file name or location, both of which are obviously not user friendly.

0

1 Answer 1

2

All of you need to do is to Add New Regions to your Theme like logo_region and then print the site logo on desired twig template with below code:

{% if logo_region %}
  <div class="my-style">
    {{ page.logo_region }}
  </div>
{% endif %}

And finally enable/place your site brand in created region (logo_region) on Block layout page:admin/structure/block

2
  • Sounds good thank you! I was hoping for more simple way, but as this is the most user friendly and fool proof method, I happily accept it. Thanks again!
    – petergus
    Commented Mar 7, 2017 at 17:36
  • @petergus : your welcome ;) Commented Mar 7, 2017 at 17:39

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.