Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webfactory/webfactorynavigationbundle
Allows to define the tree structure and to render website navigation menus
https://github.com/webfactory/webfactorynavigationbundle
bundle navigation php symfony
Last synced: 9 days ago
JSON representation
Allows to define the tree structure and to render website navigation menus
- Host: GitHub
- URL: https://github.com/webfactory/webfactorynavigationbundle
- Owner: webfactory
- License: mit
- Created: 2015-07-24T13:54:55.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-01-08T18:28:40.000Z (10 months ago)
- Last Synced: 2024-04-09T11:08:15.740Z (7 months ago)
- Topics: bundle, navigation, php, symfony
- Language: PHP
- Homepage:
- Size: 210 KB
- Stars: 3
- Watchers: 8
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
WebfactoryNavigationBundle
==========================Symfony Bundle featuring:
- A factory for creating the navigation tree, using BuildDirectors which you can add to, if needed
- Twig functions for rendering navigation elements (tree, ancestry, breadcrumbs) and inspecting the navigation treeInstallation
------------composer require webfactory/navigation-bundle
... and activate the bundle in your kernel, depending on your Symfony version.
Rendering navigation elements in Twig
-------------------------------------### Simple Navigation List
#### Syntax
{{ navigation_tree(root, maxLevels = 1, expandedLevel = 1, template = '@WebfactoryNavigation/Navigation/navigation.html.twig') }}
#### Examples
{{ navigation_tree(root = {"webfactory_pages.page_id": root_page_id}) }}
{{ navigation_tree(
root = {"webfactory_pages.page_id": root_page_id, "_locale": app.request.locale},
template = 'AppBundle:Navigation:navigation.html.twig'
) }}### Ancestry List
An ancestry list is the active path from the given start level to the currently active node. Useful if you want to render
e.g. the third level navigation outside of the regular navigation.#### Syntax
{{ navigation_ancestry(startLevel, maxLevels = 1, expandedLevels = 1, template = '@WebfactoryNavigation/Navigation/navigation.html.twig') }}#### Examples
{{ navigation_ancestry(startLevel = 1) }}
{{ navigation_ancestry(startLevel = 1, template = '@App/Navigation/secondaryNav.html.twig') }}### Breadcrumbs
#### Syntax
{{ navigation_breadcrumbs(template = '@WebfactoryNavigation/Navigation/breadcrumbs.html.twig') }}
#### Examples
{{ navigation_breadcrumbs() }}
{{ navigation_breadcrumbs(template = '@App/Navigation/breadcrumbs.html.twig') }}### Customisation
For each function mentioned above you can provide a Twig template in which you can extend the base template and
overwrite each block. Please find the default blocks in `src/Resources/views/Navigation/navigationBlocks.html.twig`.Example:
```twig
{# layout.html.twig: #}...
{{ navigation_tree(root = {"webfactory_pages.page_id": root_page_id}, template = 'AppBundle:Navigation:navigation.html.twig') }}
...
``````twig
{# AppBundle:Navigation:navigation.html.twig: #}{% extends "@WebfactoryNavigation/Navigation/navigation.html.twig" %}
{% block navigation_list %}
{{ parent() }}
{% endblock %}
```Modifying the NavigationTree
----------------------------Implement a `Webfactory\Bundle\NavigationBundle\Build\BuildDirector`. Example:
```php
repository = $repository;
$this->objectRouter = $objectRouter;
}public function build(BuildContext $context, Tree $tree, BuildDispatcher $dispatcher): void
{
if (!$this->isInterestedInContext($context)) {
return;
}foreach ($this->repository->findForMenu() as $entity) {
$context->get('node')
->addChild()
->set('caption', $entity->getName())
->set('visible', true)
->set('url', $this->objectRouter->path('detail', $entity));
}$this->addResourcesToTreeCache($dispatcher);
}private function addResourcesToTreeCache(BuildDispatcher $dispatcher): void
{
$dispatcher->addResource(new FileResource(__FILE__));
$dispatcher->addResource(new DoctrineEntityClassResource(YourEntity::class));
}
}
```Define your implementation as a service and tag it `webfactory_navigation.build_director`. Example:
```xml
```
See `src/Resources/doc/How-To-Use-Klassendiagramm.puml` for more.
Credits, Copyright and License
------------------------------This project was started at webfactory GmbH, Bonn.
-
-Copyright 2015 - 2021 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).