# Create alias for alternate view format

I've just created an RSS feed view format for one of the views in my component. This is contained in:

I tried creating a hidden menu item for it with an alias of 'rss'. However, I don't know of a way to create a menu item for an alternate view format other than using an External URL menu type (under System Links), and such menu items are not accessible via their alias as far as I can determine. Is there some other way of achieving this?

You could accomplish this in your component's route.php file. The particulars would depend on how your routing in route.php is done so I can't give you an exact answer but I think you'd need to update your parse() method to include something like this the beginning:

public function parse(&$segments) { if(count($segments)==1 && $segments[0]=='rss') {$item = $this->menu->getActive();$vars = $item->query;$vars['format'] = 'feed';
$vars['type'] = 'rss'; return$vars;
}

[...]

}

What you're essentially trying to do is look for a "/rss" segment in the URL and, when found, setting the format and type variables so that route/request is executed. In other words, you're making /rss and alias for ?format=feed&type=rss on whatever URL you add /rss to for that component.

Hope this helps!

• That'll do the trick alright! – John Rix Oct 24 '17 at 22:08
• Actually, I jumped the gun a little there. The above won't work, since the Joomla routing process has already chosen the document type to be 'html' by the time my own component router is invoked - consequently, setting $vars['type'] = 'rss'; has no effect. Instead, I had to invoke JFactory::getDocument()->setType('rss'); (and did not need to set the 'format' var). It still doesn't quite feel like the 'correct' solution for some reason, but it works. – John Rix Oct 24 '17 at 22:53 • Hmm, The component's router should fire after the correct menu item is found while parsing the URL. Ex, if the URL path is x.com/menu-item/submenu-item/rss then joomla will find any menu item with alias menu-item, then any child menu item (of menu-item) with alias submenu-item and then attempt to find a child menu item (of submenu-item) with alias rss. Since the rss menu item isn't found Joomla will use/set the vars from submenu-item and then pass rss into the component's route.php->parse() method as the$segments variable. If rss wasn't there (and nothing else was after... – Drew G Oct 25 '17 at 13:36
• Perhaps the difference is in the fact that the view being used is the default view for my site (it is set as the home page in the Main Menu) and hence the complete URL is just '/rss'. – John Rix Oct 25 '17 at 13:41
• ... submenu-item) then the parse() method wouldn't even be called. But because there is something after submenu-item (and that something isn't a valid child menu alias of submenu-item) then parse() will be called. Any vars returned by parse() should overwrite the vars that were added from submenu-item before parse() was called. If you want to check out where this is happening see /libraries/src/Route/SiteRouter.php -> parseSefRoute(). Line 419 sets the vars from the menu item (submenu-item in my example) and line 439 is where the router.php->parse()'s vars are then added. – Drew G Oct 25 '17 at 13:41