Skip to content

Commit

Permalink
chore: better menu (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
COil authored Dec 24, 2024
1 parent cebaeeb commit 66a16c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/Twig/Extension/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function getFunctions(): array
return [
new TwigFunction('ctrl_fqcn', $this->getControllerFqcn(...)),
new TwigFunction('attr_if', $this->getAttributeIf(...)),
new TwigFunction('aria_current_page_if', $this->getAriaCurrentPageIf(...)),
];
}

Expand Down Expand Up @@ -85,4 +86,9 @@ public function getAttributeIf(bool $condition, string $attribute, string $value

return \sprintf(' %s="%s"', $attribute, $value);
}

public function getAriaCurrentPageIf(bool $condition): string
{
return $this->getAttributeIf($condition, 'aria-current', 'page');
}
}
10 changes: 5 additions & 5 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
Menu
</summary>
<ul role="group-menu">
<li><a href="{{ path(ctrl_fqcn('HomeAction')) }}"{{ attr_if(app.current_route == ctrl_fqcn('HomeAction'), 'aria-current', 'page')|raw }}>📒 README</a></li>
<li><a href="{{ path(ctrl_fqcn('HelloWorldAction')) }}"{{ attr_if(app.current_route == ctrl_fqcn('HelloWorldAction'), 'aria-current', 'page')|raw }}>Hello world! 👻</a></li>
<li><a href="{{ path('App\\Controller\\StimulusAction') }}"{{ attr_if(app.current_route == 'App\\Controller\\StimulusAction', 'aria-current', 'page')|raw }}><b>J</b>ava<b>S</b>cript with Stimulus</a></li>
<li><a href="{{ path(ctrl_fqcn('ComposerAction')) }}"{{ attr_if(app.current_route == ctrl_fqcn('ComposerAction'), 'aria-current', 'page')|raw }}>The <code>composer.json</code> file</a></li>
<li><a href="{{ path(ctrl_fqcn('FormAction')) }}"{{ attr_if(app.current_route == ctrl_fqcn('FormAction'), 'aria-current', 'page')|raw }}>📝 Form example</a></li>
<li><a href="{{ path(ctrl_fqcn('HomeAction')) }}"{{ aria_current_page_if(app.current_route == ctrl_fqcn('HomeAction'))|raw }}>📒 README</a></li>
<li><a href="{{ path(ctrl_fqcn('HelloWorldAction')) }}"{{ aria_current_page_if(app.current_route == ctrl_fqcn('HelloWorldAction'))|raw }}>Hello world! 👻</a></li>
<li><a href="{{ path('App\\Controller\\StimulusAction') }}"{{ aria_current_page_if(app.current_route == 'App\\Controller\\StimulusAction')|raw }}><b>J</b>ava<b>S</b>cript with Stimulus</a></li>
<li><a href="{{ path(ctrl_fqcn('ComposerAction')) }}"{{ aria_current_page_if(app.current_route == ctrl_fqcn('ComposerAction'))|raw }}>The <code>composer.json</code> file</a></li>
<li><a href="{{ path(ctrl_fqcn('FormAction')) }}"{{ aria_current_page_if(app.current_route == ctrl_fqcn('FormAction'))|raw }}>📝 Form example</a></li>
<li><a href="{{ app.environment == 'dev' ? '/_error/404.html' : '/404' }}">❌ Custom error page</a></li>
<li><a href="https://picocss.com/docs" target="_blank">✨ Pico CSS documentation ⤴️</a></li>
</ul>
Expand Down

0 comments on commit 66a16c3

Please sign in to comment.