9
Joomla! Routing Explained

Joomla! Itemid amd routing explained

Embed Size (px)

Citation preview

Page 1: Joomla! Itemid amd routing explained

Joomla! Routing Explained

Page 2: Joomla! Itemid amd routing explained

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

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

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

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

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

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

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

Thanks !Ashwin Date | techjoomla.com | @coolbung