How to fix problem with relative path Joomla for a module using editor form field?

Joomla Asked by astridx on September 5, 2021

I have created one module in Joomla and added one form field of the type editor inside the manifest-XML.


It is possible to insert an image via this editor.

Everything works fine in the front end view, if there is no submenu. I mean: If the URL is joomla-cms/ the images are shown correcly.
But if the URL is joomla-cms/index.php/home/mysubmenu because I view the module in a submenu. The picture link is broken.

I had a look at the Joomla Core Module mod_custom. This module uses the tag <customContent />. I think I can not use this tag, because I need more than one editor field in my module.

One other solution would be to enter image path absolute. I do not want that. Is there another solution?

One Answer

I've now discovered that I need to insert a slash in front of the URL to load from the root directory. For example: /joomla-cms/images/joomla_black.png.

This is not good because many editors simply delete this slash. Also, the URL is not really relative anymore. It can not be easily used in a subdirectory anymore - for example in an test envirement with xampp.

Then I found out that the Joomla SEF system plugin could not be activated. That plugin is for does checking and correction the relative path. This was not the problem for me either. The plugin was active. In my case, the plugin has been bypassed because I use the input in JavaScript.

Therefore, I change now the editor input in my JavaScript file myself. I store the URL before in php.

<div data-uriroot='<?php echo JUri::root(); ?>'></div>

Then I paste this line in JavaScript.

var uriroot = element.getAttribute('data-uriroot');
MEINE_DITORTEXT.replace(/<img src="images/g, '<img src="' + uriroot + 'images')

Maybe another person might need it?

Answered by astridx on September 5, 2021

Add your own answers!

Related Questions

Generating a module instance from PHP

0  Asked on September 5, 2021 by ffrewin


Embed custom JS app in Joomla MVC

0  Asked on September 5, 2021 by miasto


Error when updating Gantry from 4.1.20 to 4.1.32

1  Asked on September 5, 2021 by norberto-gomes


Change user permissions programmatically on the fly

1  Asked on September 5, 2021 by aheavyobject


Akeeba backup update broke the site

2  Asked on September 5, 2021 by hamlet-kraskian


Proper way for autoloading in Joomla 4

1  Asked on September 5, 2021 by webchun


Menu Specifically For Super Users

1  Asked on September 5, 2021


Joomla PHP does not match host PHP

2  Asked on February 18, 2021


Controller Joomla – Output Class construct for color css style

1  Asked on February 5, 2021 by andrea-suriani


Joomla custom component – router not find alias

1  Asked on January 21, 2021 by lecraver


Joomla 3 call model function inside controller

3  Asked on December 28, 2020 by wbdevlop


Product url problem after updating VirtueMart

1  Asked on December 23, 2020 by kiasaty


Display intro image inside mod_breadcrumbs

0  Asked on November 11, 2020 by geoplous


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP