Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
When a menu is rendered in the ul tag we can easily find the nav and menu class what is practical to use to target our styles; however if we need to target specific styles to specific menus we don't have the posibility to target that concrete menu.
In the template "templates/menu/menu.html.twig" the menu_name value is available but not included in the macro.
This is a patch that includes the menu machine name as attribute and will help with this need.
Comments
Comment #2
casivaagustin CreditAttribution: casivaagustin commentedComment #3
bandanasharma CreditAttribution: bandanasharma as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedComment #4
bandanasharma CreditAttribution: bandanasharma as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commented#2 patch is apply successfully. I have attached the after and before attachment.
Comment #5
markhalliwellSince this is a variable (machine name), then it should use the
|clean_class
filter as well when adding it.Comment #6
markhalliwell@bandanasharma, taking screenshots of code changes isn't necessary and honestly, a little confusing; that is what the patch is for.
Screenshots are typically only useful for changes that affect the UI/site itself.
Comment #7
casivaagustin CreditAttribution: casivaagustin at 42mate commentedHere goes a patch for the comment #6.
Comment #8
casivaagustin CreditAttribution: casivaagustin at 42mate commentedComment #9
casivaagustin CreditAttribution: casivaagustin at 42mate commentedBump: Ready for Review
Comment #10
gerzenstl CreditAttribution: gerzenstl at 42mate commentedThe last patch looks good.
Comment #11
sylus CreditAttribution: sylus commentedI might have missed something but I see that the following code was directly removed? Was that by design?
Comment #12
markhalliwellThere was a lot of markup/line changes between #2 and #7. I just asked that the
|clean_class
filter was applied. I don't think the level of complexity in #7 is needed.Comment #13
casivaagustin CreditAttribution: casivaagustin at 42mate commentedHere goes a new patch, like #2 but adding the clean_class
Thanks for the feedback
Comment #14
casivaagustin CreditAttribution: casivaagustin at 42mate commentedComment #15
markhalliwellNever override existing variables in templates. This can cause unintended and unforeseen issues when attempting to extend or override in sub-themes.
The filter should be used like the following (without spaces around the pipe):
<ul{{ attributes.addClass('dropdown-menu', menu_name|clean_class) }}>
Comment #16
casivaagustin CreditAttribution: casivaagustin at 42mate commentedD'oh!, Here it goes without override the variable.
Thanks for the feedback
Comment #17
casivaagustin CreditAttribution: casivaagustin at 42mate commentedComment #18
casivaagustin CreditAttribution: casivaagustin at 42mate commentedOne more time, I miss out something from the comment.
Comment #20
markhalliwellComment #22
markhalliwellJust an FYI: #2936370: Consolidate menu macro in main template
This adds a
menu--
prefix to the menu name.