I created a custom theme called wdocs as a sub theme of d8w3css. I made a template to override the menu template for the user account menu, calling it menu--account.html.twig. For my theme, I added the function wdocs_preprocess_menu__account()
to my wdocs.theme file, and introduced a new variable with $variables['tollfree_number'] = '555-1212'
; So far so good; in phpStorm I can set a breakpoint there are do see it is getting set in $variables. In my twig, I have some text, followed by {{ tollfree_number }}
. The text gets displayed, but not the variable.
The problem is the twig calls a macro; I can access the var outside of the macro, but not within it. Googling suggested I pass context when calling the macro, so I changed the call to
{{ menus.menu_links(items, attributes, 0, menu_name, _context) }}
I also tried "context" (no underscore). And also tried dereferencing it with {{ _context['tollfree_number'] }}
, but nothing seems to help. Where am I going wrong?