Link to articles from another component (J3)

40 views
Skip to first unread message

roger...@googlemail.com

unread,
Mar 24, 2022, 8:58:39 AM3/24/22
to Joomla! General Development
So I am developing a component and in the front-end views I have links to articles. However Joomla seems to be corrupting the links whether or not SEF is turned on.

In the component view I have a link


<?php $alink = 'http://j3.localhost/index.php?option=com_content&view=article&id=4'; ?> <a href="<?php echo $alink; ?>">Link to article 4</a>
If I enter that link directly in the address bar the page shows, however clicking the link from within my component Joomla has corrupted the url to be "http://j3.localhost/index.php>id=4" which of course doesn't do anything.

If SEF is turned on and there happens to be a menu entry linking to article 4 as (say "Article4") then for that article Joomla makes the link "http://j3.localhost/article4" which works, but for any other article which doesn't have a menu entry it doesn't.

There is a menu entry for "Home" which links to the default page at "index.php"

SO my problem is, how to make links to articles from another component (not com_content) work. I have tried putting something in a site/helpers/route.php that parses the link, but it only gets redirected to /mycomponent/article rather than /content/article.

Any clues anyone. (PS my component router.php and helpers/route.php work fine for links to my own component's views. It is the cross linking to com_content that I can't get to work)

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Søren Beck Jensen

unread,
Mar 25, 2022, 6:54:30 AM3/25/22
to joomla-de...@googlegroups.com
You need to read this: https://docs.joomla.org/J3.x:Supporting_SEF_URLs_in_your_component

But basically you need to use 

\Joomla\CMS\Router\Route::_('index.php?option=com_content&view=article&id=4');


--

SOREN BECK JENSEN

DIRECTOR


Jensen Technologies

jensen.technology  

+34 858 28 40 04

Book a meeting with me!



--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/4202635a-db64-4563-8893-0418e717aaban%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages