Skip to content

Commit

Permalink
fix: update menu usage (#78)
Browse files Browse the repository at this point in the history
- Adds comments to clarify how multiple menus could be used
- Removes unused items variable from menu include
- Changes Timber Menu argument to use correct menu
  • Loading branch information
rise-erpelding authored Oct 9, 2023
1 parent 43639f8 commit c55c5bc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/php/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* @return array
*/
function add_to_context( $context ) {
$context['menu'] = new \Timber\Menu( 'primary-menu' );
$context['menu'] = new \Timber\Menu( 'primary' );
$context['footer_sidebar'] = Timber\Timber::get_widgets( 'footer-area' );
return $context;
}
Expand Down
7 changes: 6 additions & 1 deletion src/php/inc/theme-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ function sparkpress_theme_setup() {
*/
add_theme_support( 'post-thumbnails' );

register_nav_menus( array( 'primary' => 'Primary' ) );
register_nav_menus(
array(
'primary' => 'Primary',
// register additional menus
)
);

/*
* Switch default core markup for search form, comment form, and comments
Expand Down
2 changes: 1 addition & 1 deletion src/php/views/header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<a href="{{ site.url }}" class="cmp-main-nav__home-link" rel=" home">{{ site.name }}</a>
</div>
<nav class="cmp-main-nav__menu" aria-label="Main">
{% include "menu.twig" with {'items': menu.get_items} %}
{% include "menu.twig" %}
</nav>
</div>
{% endblock %}
Expand Down
1 change: 1 addition & 0 deletions src/php/views/menu.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# can specify menu when including template #}
{% if menu %}
<ul class="cmp-main-nav__list">
{% for item in menu.items %}
Expand Down

0 comments on commit c55c5bc

Please sign in to comment.