0

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

<field
    type="editor"
    name="myeditor"
    default=""
    buttons="true"
    hide="pagebreak,readmore"
    label="MOD_TEST"
    description="MOD_TEST_DESC"
    filter="safehtml"
/>

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?

  • What is the URL of the image when it works and when it doesn't? It sounds like the image URL is relative to something. – Irata Oct 21 at 0:13
  • Thanks for your answer, and yes, the relativness is the problem. The URL of the image is all the time 'images/joomla_black.png'. It works on the home menu item: localhost/joomla-cms In a submenu, for example on the URL 'localhost/joomla-cms/index.php/home/submenu' it does not work. So my question is: How can I insert an editor form field (docs.joomla.org/Editor_form_field_type) into a joomla module and achieve that pictures inserted via the editor form field can also be found in submenus (relative). – astridx Oct 21 at 9:27
  • The URL of the images appears to be correct in that it is relative to the Joomla root directory and is not or should not be getting affected by a change in Menu. Have you tried to update the image URL with the full URL, i.e. www.mysite.com/images/joomla_black.png to see if the problem still occurs? – Irata Oct 21 at 9:43
  • Thank you. Yes, I tried the absolute URL. That is fine. But do not want to use an absolute URL. – astridx Oct 21 at 9:52
0

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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