Advertisement

Custom plugin for routing

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
nabbo
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Apr 05, 2018 11:04 am

Custom plugin for routing

Post by nabbo » Fri Jan 24, 2025 12:16 pm

In joomla 3 I use the "simple custom router manager" plugin where I configured a regex rule with which I can render a menu item (article).
How can I replicate the same thing in joomla 5?

I tried to create a custom plugin but I end up on the 404 page.

Code: Select all

<?php
defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;

class PlgSystemCustomRouter extends CMSPlugin
{
    public function onAfterInitialise()
    {
        $app = Factory::getApplication();

        if ($app->isClient('site'))
        {
            $input = $app->input;
            $uri  = Uri::getInstance();
            $path = $uri->getPath();

            if (preg_match('#^viaggi/(\d+)-([a-zA-Z0-9-]+)$#', $path)) {
                $input->set('option', 'com_content');
                $input->set('view', 'article');
                $input->set('id', 2);
                $input->set('Itemid', 104);   
            }
        }
    }
}
You do not have the required permissions to view the files attached to this post.

Advertisement
Priyasharma
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Mon Jan 27, 2025 9:05 am

Re: Custom plugin for routing

Post by Priyasharma » Mon Jan 27, 2025 9:36 am

In Joomla 5, custom routing is handled differently. You’ll need to use the new Joomla 5 routing system, potentially extending the Router class or using a custom plugin with a route handler. Check the documentation for updated routing methods, as the old plugin may not apply directly.

nabbo
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Apr 05, 2018 11:04 am

Re: Custom plugin for routing

Post by nabbo » Mon Jan 27, 2025 9:47 am

where is documentation about new system routing for joomla 5? I found only documentaiton for joomla 2.5/3!

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25377
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Custom plugin for routing

Post by pe7er » Mon Jan 27, 2025 1:33 pm

nabbo wrote: Mon Jan 27, 2025 9:47 am where is documentation about new system routing for joomla 5? I found only documentaiton for joomla 2.5/3!
See the Joomla Programmers Documentation for Joomla 5.2:
https://manual.joomla.org/docs/general- ... s/routing/
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

nabbo
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Apr 05, 2018 11:04 am

Re: Custom plugin for routing

Post by nabbo » Mon Jan 27, 2025 5:43 pm

Unfortunately it is beyond my capabilities.
What I am trying to do, is it possible to do it with a plugin or is a component necessary?

Advertisement

Post Reply

Return to “Joomla! 5.x Coding”