The
Navigation component is responsible for displaying the path to the main content of a page. Also the name Bread Crumb Navigation has become quite common among developers. This component tries to determine itself what path to display because it tries to find this path within the menu structure.
How the Navigation Component Finds a Path
If it finds the menu item that leads to displaying the actual page, the component displays the name of such item and inserts the path leading just to this item within the menu before it. If it meets with any item having set a link (either a direct link or a combination of a link section and a display mode) on this path, it creates the same link from the item of this path as the corresponding menu item has.
For example, if you have the following structure within the menu:
Magazine
- Style
- Hi-tech
- Fashion
- Watches
- Gastronomy
- Travelling
- Sport
where all items link to the
Articles link section and the
List of Records display mode connected to this menu item, then on clicking on
Watches the list of articles will be displayed and the Navigation component will display:
Home > Magazine > Style > Watches
The
Magazine and
Style items will have their own link leading to the list of articles, the
Watches item will be without any link because there is no use in the page linking to it itself.
On clicking on a particular article, the name of that article will be displayed and the full path before it. This time all the items will have their links with the exception of the one with the article name. Again, there would be no use in displaying a link linking to it itself.
Home > Magazine > Style > Watches > Article Name
How to Display Custom Values in the Navigation Component Output?
If the Navigation component is unable to determine itself the correct path (e.g. there is no adequate menu item) or you require your own display for any reasons, it is possible to determine for this component what it shall display. For every table, the
onGetNavigation event can be defined. If you display the main content of a certain table and such table has defined this event, then the Navigation component will display the values from the field that you will return just by this event. An advantage of setting this event for particular tables is the option to retain the default display for all the other tables.
You can use the following variables in the
onGetNavigation event:
| $this |
A table object. |
| $viewType |
A display mode ("vtList", "vtFull"). |
| $navigation |
The initial field with a navigation path created by the Navigation component. |
In the example, we display all articles of an author. There is the
author field in the
articles table that contains the login of the author of an article. Authors of articles are stored in the
admin_users table. Let’s have the
articles.php?filter_author=novak link and we want to display also the information that we are searching by author in the path displayed by the Navigation component for this type of link.
We will enter the following code into the
onGetNavigation event, the
articles table:
if ($viewType == "vtList" && $filter_author != "")
{
// I will load the record of the author to get the whole his name
$record = getTable("admin_users")->getRecord("filter=login='".$filter_author."'");
$navigation = array(
array("name" => "Articles", "url" => "articles.php"),
array("name" => "Articles of the Author ".$record["name"], "url" => "articles.php?filter_author=".$record["login"]),
);
return($navigation)
}
else
{
// if it to be to the contrary, we give back the initial path
return($navigation);
}
In this case, the component will display:
Home > Articles > Articles of the Author Jan Novák