Difference between revisions of "How to add breadcrumbs"
From Joomla! Documentation
m (Typo) |
(Some markup, URL and language changes.) |
||
Line 7: | Line 7: | ||
<translate> | <translate> | ||
<!--T:2--> | <!--T:2--> | ||
− | Breadcrumbs are nice way to display the connection from the root. It gives you a hierarchical representation with | + | Breadcrumbs are a nice way to display the connection from the root. It gives you a hierarchical representation with clickable links so that user can visit upper links easily. Breadcrumbs can be added in templates by using the object returned by ''$mainframe->getPathWay()''. The member function ''addItem()'' allows you to add a breadcrumb with the title of your choice.</translate> |
<translate> | <translate> | ||
<!--T:3--> | <!--T:3--> | ||
− | There are two parameters used for breadcrumbs creation process | + | There are two parameters used for breadcrumbs creation process. The first is the title for the breadcrumb and the second is the URL. If we do not need the breadcrumb to work as a link then we simply pass a blank string and it will not be a clickable URL. This term is useful for hierarchical components where we have subcategories: we can generate a link to each and then end with the title of the current record or category. |
</translate> | </translate> | ||
<translate> | <translate> | ||
<!--T:4--> | <!--T:4--> | ||
− | The JPathway is | + | The ''JPathway'' is used by the breadcrumbs module. If you are adding a new component and have already configured breadcrumbs, you may need to go into the breadcrumbs configuration and add the menu item of your component to the menu selection list. |
</translate> | </translate> | ||
== Example == | == Example == | ||
{{JVer|{{CurrentSTSVer|minor}}}} <translate><!--T:5--> | {{JVer|{{CurrentSTSVer|minor}}}} <translate><!--T:5--> | ||
− | The display function from a view's view.php for Joomla! 3.x could look | + | The display function from a view's ''view.php'' for Joomla! 3.x could look like this.</translate> |
− | < | + | <syntaxhighlight lang="php"> |
− | public function display($tpl = null) | + | public function display($tpl = null) |
{ | { | ||
− | + | ||
$app = JFactory::getApplication(); | $app = JFactory::getApplication(); | ||
$pathway = $app->getPathway(); | $pathway = $app->getPathway(); | ||
Line 34: | Line 34: | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
<translate> | <translate> | ||
− | == See Also== <!--T:6--> | + | == See Also == <!--T:6--> |
− | * [ | + | * [https://api.joomla.org/cms-2.5/classes/JPathway.html JPathway in the Joomla! API] |
− | |||
− | |||
</translate> | </translate> | ||
Latest revision as of 18:23, 19 October 2022
Breadcrumbs are a nice way to display the connection from the root. It gives you a hierarchical representation with clickable links so that user can visit upper links easily. Breadcrumbs can be added in templates by using the object returned by $mainframe->getPathWay(). The member function addItem() allows you to add a breadcrumb with the title of your choice.
There are two parameters used for breadcrumbs creation process. The first is the title for the breadcrumb and the second is the URL. If we do not need the breadcrumb to work as a link then we simply pass a blank string and it will not be a clickable URL. This term is useful for hierarchical components where we have subcategories: we can generate a link to each and then end with the title of the current record or category.
The JPathway is used by the breadcrumbs module. If you are adding a new component and have already configured breadcrumbs, you may need to go into the breadcrumbs configuration and add the menu item of your component to the menu selection list.
Example[edit]
The display function from a view's view.php for Joomla! 3.x could look like this.
public function display($tpl = null)
{
$app = JFactory::getApplication();
$pathway = $app->getPathway();
$pathway->addItem('My Added Breadcrumb Link', 'http://www.yourdomain.tld');
parent::display($tpl);
}