Adding more variables to menu for use in menu.html.twig I'm attempting to give menus more variables to work with besides the default menu_name,items, and attributes. This is because making a variable in the preprocess menu hook does not allow it to be accessible in the menu.html.twig template.

My ultimate goal is to be able to add menu items that contain the user id in the path. 

I believe I need to add the var to menu by using hook_theme_registry_alter and follow the format of https://api.drupal.org/api/drupal/core%21includes%21theme.inc/function/drupal_common_theme/8.2.x

So I attempted to add a variable to menu in my .theme file like so

function mytheme_theme_registry_alter(&amp;$theme_registry){
    $theme_registry['menu']['variables']['test_var'] = 'testing theme registry alter';
}


But when I do so nothing appears when I alter menu.html.twig like so

&lt;nav {{ attributes.addClass(navClasses) }} aria-label="MyWPT Menu Mobile" role="navigation" style="display:none;"&gt;
    {{ menus.menu_links(items, attributes, 0) }}
{#     {% macro menu_links(items, attributes, menu_level) %} #}
    {% macro menu_links(items, attributes, menu_level) %}
    {% import _self as menus %}
    {% if items %}
    {% if menu_level == 0 %}
    &lt;ul class="vertical menu" data-drilldown&gt;
        {% else %}
        &lt;ul class="vertical menu"&gt;
            {% endif %}
            {% for item in items %}
                {% if item.below %}
                    &lt;li class="is-dropdown-submenu-parents"&gt;
                {% else %}
                    &lt;li{{ item.attributes }}&gt;
                {% endif %}
                {{ link(item.title, item.url) }}
                {% if item.below %}
                    {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
                {% endif %}
                &lt;/li&gt;
            {% endfor %}

            &lt;li&gt;&lt;a href="/"&gt;{{ test_var }}&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
        {% endif %}
        {% endmacro %}


How would I add more menu variables for use in menu.html.twig ?

UPDATE: I also tried {{menus.test_var}} but that just broke the page

UPDATE 2: Using {{ kint() }} the test_var did not appear anywhere
Here is an example from a real project I had done:
mytheme.theme:
/**
 * Implements hook_theme_registry_alter().
 * @param $theme_registry
 */
function mytheme_theme_registry_alter(&amp;$theme_registry) {
  $theme_registry['menu']['variables']['top_parent'] = [];
}

/**
 * Implements hook_preprocess_block__menu_block().
 * @param $variables
 */
function mytheme_preprocess_block__menu_block(&amp;$variables) {
  // set the top parent on the left nav
  if ($variables['elements']['#id'] == 'left_navigation' &amp;&amp; !empty($variables['elements']['content']['#items'])) {
    // code removed

    $variables['content']['#top_parent'] = [
      'title' =&gt; $menu_content-&gt;getTitle(),
      'url' =&gt; $menu_content-&gt;getUrlObject(),
      'is_current' =&gt; ($current_path == $item_path)
    ];
  }

  // code removed
  }
}

In Twig:
  {% if menu_level == 0 %}
    &lt;li class=&quot;left-nav__item active-trail is-active {% if top_parent.is_current %}is-current{% endif %}&quot;&gt;
      {{ link(top_parent.title, top_parent.url) }}
    &lt;/li&gt;
  {% endif %}

You are likely missing the part where you add test_var key to the content array:
$variables['content']['#test_var'] = &quot;whatever&quot;;
With exception to flagging is-current, it looks like you're trying to do the same thing I did. You should strive to use the link function in Twig instead of a hard coded anchor unless there is no way around it.