# Menu
The menu in the template-www can be easily customized using the intuitive MAYS UI. To access and configure it, utilize the WebRoute and WebTemplate schemas accessible through the Site Management option. The Menu and Templates are closely interconnected, allowing you to tailor your website's navigation precisely to your needs.
Each menu entry offers flexible configuration options, allowing you to define its behavior and appearance. Here are the supported attributes:
Title: This is the name displayed on your website.This name is translatable and generates the urlseo used to access the page.
Type: Depending on your requirements, you can choose from two options:
- Link/Anchor: This creates a simple hyperlink, permitting you to specify anything you would typically include in the
hrefattribute of an<a>tag. - Template: If you opt for a Template, you must select which template to use. Further details are provided below for your convenience.
- Link/Anchor: This creates a simple hyperlink, permitting you to specify anything you would typically include in the
Menu: Decide in which menu this item should appear, whether it's the header, footer, or both. If you have custom menus in mind, you can easily create them by adding the options to the
rsdata source in the field configuration.Parent: This attribute specifies which menu item serves as the parent of the current one. It's particularly useful for creating submenus. If an item is designated as a submenu, the "menu" attribute above is disregarded, and this item will only appear as a child of its parent. Please note that only one level of submenu is supported.
Banner: If you wish to include a custom banner with a menu entry, you can do so by adding the necessary code manually to the twig template.
Requires Authentication: By enabling this option, you restrict access to the route, making it available only to logged-in users. Specifically, this means that the route will be accessible if a
$_SESSION['user_id']is set on the current page.
With these configuration options, you can effortlessly create a dynamic and user-friendly menu for your website, ensuring a seamless and engaging user experience.
# Template utils function
Within the template, the routing and menu functionality are primarily managed by four key classes: Router, Route, Menu, and MenuItem.
# Router
The Router class plays a pivotal role in managing the routing functionality of your template.
If you just want to get started you can manualy add into routes.php a new entry for a route.
'search-results-unique-key' => [
'path' => [
new Translatable(["search-results-slug"])
],
'title' => new Translatable(["Search Results Title Example"]),
'full_title' => [new Translatable(["Full title"])],
'handler' => 'SearchResults'
]
Notice that the handler should match a PHP class that is created on the folder core/pages.
Yet it's advised that you should create the routes rules using the MAYS UI (CMS).
Create new Page Templates
You can run the mays-cli to easily create PHP handler class, twig template and a SCSS file for the template by just running php mays-cli.php create:page.
# Route
The Route class is responsible for defining individual routes and their associated behaviors.
TODO Needs examples, how can I access current route? Or a route by name? Or the slug when using urlseo? Or how I inject url on a result set of a list from a given schema.
# Menu/MenuItem
The Menu class is crucial for generating the HTML structure of your menu and handling the respective CSS classes. For consistent and uniform code, it's highly recommended to utilize the components/menu.twig template whenever possible.
The MenuItem class complements the Menu by representing individual menu items. You can generate a manual menu if you create an array of MenuItem and looping through each one calling the computeAttributes() method of the class.
To streamline the menu generation process, the Menu class offers the Menu->getMenu($menu) function. This function generates an array of the MenuItem of the corresponding Menu configured through the MAYS UI (header, footer or both).
In summary, these four classes work in tandem to provide robust routing and menu management capabilities for your template. By following best practices and utilizing the provided components and functions, you can maintain code consistency and create an efficient and user-friendly website navigation system.
← Snippets