0

Let me explain. I have created a custom component, when editing the element and saving it once, I would like to display next to the alias the sef frontend link to this element. Here is a screenshot to explain :

screenshot

I haven't coded anything yet because I'm not sure how to do it?

1 Answer 1

1

I'm assuming that since you're asking about SEF URLs for your component that you've already built your own custom router (as SEF URLs for a custom component are dependent upon that). If not then you can follow the example described in https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_an_alias and following tutorial steps.

If you've done that then outputting an SEF URL on the admin backend is similar to how you create an SEF URL on the front end using JRoute::_ and passing the various parameters such as your component (option), id of your item, Itemid of the menuitem, etc. Except that on the admin side you should use

use Joomla\CMS\Router\Route; 
$url = Route::link("site", "index.php?option=com_example&view=showitem&id=14);

See Joomla Route link for the API definition and URLs in Joomla for a description of how to use these functions.

Note that the link method is available only since Joomla 3.9, so if you're working on a version which predates that then it's rather more tricky, as you have to hack your way into the Joomla core code, but not impossible.

Also just be aware that the SEF URL may differ depending upon the Itemid of the menuitem which you pass to the link function and how you've built your custom router.

1
  • OK, thank you, your answer gave me the right direction.
    – Laurent
    Commented Jan 20, 2021 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.