joomla! itemid amd routing explained
TRANSCRIPT
![Page 1: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/1.jpg)
Joomla! Routing Explained
![Page 2: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/2.jpg)
Anatomy of a non-sef URLindex.php?option=com_content&view=category&layout=blog&id=8&Itemid=103
![Page 3: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/3.jpg)
Itemid is king !- Notice how you write Itemid (Capital I)
- It’s the id (primary key) of the menu created
- Modules are assigned to a menu, will show up when a link having the respective Itemid shows up
- This means if you change the Itemid for any other link, a different set of modules will load. This is not desirable
- If you leave out the Itemid, only modules set to show on ‘All’ pages will show
![Page 4: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/4.jpg)
SEF URLs Explained/index.php?option=com_content&view=category&layout=blog&id=8&Itemid=103
Changes to /news
Also,
/index.php?option=com_content&view=category&layout=blog&id=9&Itemid=104
Changes to /news/sports
![Page 5: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/5.jpg)
SEF URLs Explained/index.php?option=com_content&view=article&id=7&Itemid=103
Changes to /news/7-new-article-2
/index.php?option=com_content&view=article&id=10&Itemid=104
Changes to /news/sports/10-sports-article
![Page 6: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/6.jpg)
Building a Route- Use JRoute::_() to build a route. Pass a URL with an Itemid
- Itemid creates the first section of the SEF URL
- If the query params do not match menu entry query params- The first URL section is created from the menu Itemid. Say /news/sports
- The querystring is passed to extension’s router to build the next part of the route, so it adds /10-sports-article
- This is the right way to build SEF URLs
![Page 7: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/7.jpg)
Building a Route - without Itemid- For URLs without an Itemid, or an invalid Itemid eg: index.php?
option=com_content&view=article&id=7
- JRoute makes this /component/com_content/article/?id=7
- This is the wrong way to build SEF URLs
![Page 8: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/8.jpg)
Itemid guessing- Since JRoute::_() needs an Itemid
- Write a wrapper function, say JTRoute::_() that accepts a part of the URL and guesses the Itemid
- Use this function everywhere to produce consistent URLs
![Page 9: Joomla! Itemid amd routing explained](https://reader036.vdocument.in/reader036/viewer/2022082600/58f3160a1a28ab673b8b459f/html5/thumbnails/9.jpg)
Thanks !Ashwin Date | techjoomla.com | @coolbung