Simple tool which generates menu, links and titles of pages.
$ composer require radekrepka/module-router
Configuration is in neon files.
extensions:
moduleRouter: RadekRepka\ModuleRouter\DI\ModuleRouterExtension
Then you can add your modules and pages in menu. You can set icon of item in menu. It can be anything (url to image file, fa icon...).
moduleRouter:
modules:
Presenter1:
Presenter2:
Module1: #(Admin, Costumer...)
modules:
Presenter1:
icon: home
Presenter2:
icon: ....
Module2:
modules:
Presenter1:
icon: ....
Presenter2:
icon: ....
You must create translation file called modules.
Presenter1: Some page
Presenter2: Some page 2
Module1:
_name: Module 1
Presenter1: Homepage
Presenter2: Settings
Module2:
_name: Module 2
Presenter1: ...
<?php
namespace App;
use Nette;
use Nette\Application\Routers\Route;
use RadekRepka\ModuleRouter\ModuleManager;
class RouterFactory {
use Nette\StaticClass;
/**
* @param ModuleManager $manager
* @return Nette\Application\IRouter
*/
public static function createRouter(ModuleManager $manager) {
$router = $manager->getRouter();
$router[] = new Route('[<locale=cs cs|en>/]<presenter>/<action>[/<id>]', 'Homepage:default');
return $router;
}
}
/** @var ModuleManager @inject */
public $moduleManager;
public function beforeRender() {
$modules = $this->moduleManager->getModules();
//Or from module
$modules = $this->moduleManager->getModules()->offsetGet('Module1')->getChildren();
$this->template->modules = $modules;
$this->template->currentModule = $modules->offsetGet($this->getPresenterName());
}
public function getPresenterName() {
return explode(':', $this->getName())[1];
}
<ul>
{foreach $modules as $module}
{var $active = $presenter->getName() == $module->getFullModule()}
<li{if $active} class="active"{/if}>
<a n:href="$module->getModule() . ':'">
<img n:if="$module->getIcon()" src="{$basePath}/img/{$module->getIcon()}">
<span>{$module->getName()}</span>
</a>
</li>
{/foreach}
</ul>
...
<h1>{$currentModule->getName()}</h1>