Olivero's book-tree.html.twig includes the following code:

{% if menu_level == 0 %}
  <ul{{ attributes.addClass('menu', 'menu--level-' ~ (menu_level + 1)) }}>
{% else %}
  <ul class='menu menu--level-'  ~ (menu_level + 1)>
{% endif %}

The top-level <ul> element is fine, but sub-menus are trying to increment menu--level-X classes outside of twig brackets. The code should instead be:

{% if menu_level == 0 %}
  <ul{{ attributes.addClass('menu', 'menu--level-' ~ (menu_level + 1)) }}>
{% else %}
  <ul class='menu menu--level-{{ menu_level + 1 }}'>
{% endif %}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andy-blum created an issue. See original summary.

andy-blum’s picture

Version: 9.1.x-dev » 9.2.x-dev
Status: Active » Needs review
FileSize
645 bytes
Gauravvvv’s picture

Good catch @andy-blum, This is the right approach to Adding Level Number Class to Menu Items.

RTBC +1

Madhu kumar’s picture

Patch #2 applied cleanly and it is working well to adding Level Number Class to Menu Items.

BhumikaVarshney’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
30.32 KB
26.95 KB

Hi @andy-blum,
Patch in #2 applies cleanly and working fine for me.
Thanks

mherchel’s picture

+1 RTBC on this.

It looks like this snuck in while massaging this template over from a {% set %} statement in menu.html.twig. I verified that this does not occur in any other templates.

Great catch and good fix!

Gauravvvv’s picture

I have attached before and after patch screenshots. Reference to #3.

  • lauriii committed 6ee786e on 9.2.x
    Issue #3202808 by andy-blum, mherchel: malformed twig in book-tree...

  • lauriii committed 4b2da7f on 9.1.x
    Issue #3202808 by andy-blum, mherchel: malformed twig in book-tree...
lauriii’s picture

Title: malformed twig in book-tree tremplate » malformed twig in book-tree template
Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Thank you all for looking into this issue.

Posting screenshots of your codebase does not advance the issue, since the automated testing infrastructure tells us whether the patch applies correctly. I've removed the issue credit for the screenshots. In the future, you can get credit for issues by reading the issue to understand its purpose, and posting your review or testing of that purpose. Thank you!

See the issue credit guidelines for more information.

Committed 6ee786e and pushed to 9.2.x and 9.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.