Error with macro inside navbar-brand.twig

Created on 4 November 2020, over 4 years ago
Updated 15 March 2025, 23 days ago

Problem/Motivation

The file src/components/navbar/navbar-brand.twig contains a macro to define the image used inside that component, and later on for example in the file templates/block/block--system-branding-block.html.twig, when we call it with the parameters, if for whatever reason we dont want to use the `path` parameter and it is ommited, the parameters into the macro are wrong and the width takes the value of the alt parameter.

A second error is also flagged while validating the html in both cases with the W3C validator:
If we dont have a assigned value to the height parameter and analyse the code, we get the following error:
Bad value auto for attribute height on element img: Expected a digit but saw a instead.

Steps to reproduce

- Make sure we have a logo in our site
- Create a subtheme and copy the templates/block/block--system-branding-block.html.twig file into ours (so we dont alter the radix one)
- remove the path in the copied file, or make it empty
- CR, and you will see the results: in the html, the width tag contains the alt value, and alt is empty (and in my case the sixe of the logo goes crazy)

Proposed resolution

Pass the missing parameters also in the else, (or at least a null value), like here:

{% else %}
  <span class="navbar-brand h1 mb-0 {{ utility_classes }}" aria-label="{{ text }}">
    {% if image %}
      {{ navbar_brand.image(image, width, height, alt) }}
    {% endif %}
    {{ text }}
  </span>
{% endif %}

for the second issue, the code could be as simple as:
height="{{ height|default('30') }}"
inside the macro (or any value that is related with the dimensions of the drupal logo (I forgot that '' also gives error in the validator)

Remaining tasks

User interface changes

API changes

Data model changes

Best,

πŸ› Bug report
Status

Fixed

Version

5.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium gorkagr

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024