How to use iframes in Joomla!

Advertisement:

I haven’t been working a lot with Joomla! yet, but it seems to be yet another content management system. It has its advantages (which I could not name yet), its disadvantages and its challenges. What would web-development be like without challenges?

This article has initally been published first on my old blog in native German language. To read its original in German, go to the second page of this article.

I minor challenge that I recently faced was the inclusion of “foreign” website content at another place. I’m not talking about stealing content from another site. I wanted – no, I had to – include certain text-blocks at different places on the website, but they had to be identical. To give you an example: Every online shop has its order-cancellation terms. These terms have to be included in the overall terms & conditions-section and they must be accessible as single page (by German law). Furthermore, by German law, the cancellation terms have to be shown and accepted by the user before the final checkout is being processed.

I did not like the idea of changing this text at two, three, or even more different places when there was a change needed. It would have been to easy to forget one of the text blocks, when being in a hurry. So I said to myself: Hey, basically I only want to have this text once and then include it everywhere as an iframe, where needed. This way, I only need to change the text once and it’ll automagically update on each place it has been insterted.

But Joomla! takes security very serious, so it does not allow the usage of an iframe by default. At least not with the conventional HTML-tag. Due to a security-patch some time ago, the editor will drop the opening and closing -tags – and unfortunately everything in between. Even switching from rich text editor to “no editor”, as suggested in many forums and blog entries acress the web, does not provide the desired outcome.

Finally, I found a useable solution the the Joomla! forum today. It is very simple, but to mee it seems to be more a work-around instead of a real solution.

Step-by-step solution of adding an iFrame in a Joomla! page

In principle, Joomla! names iframes as “wrappers” from version 1.5 forward. To add one, follow these steps:

  1. In the Joomla! menu bar, go to “Extensions” -> “Modules” -> “New” and choose the “wrapper” (due to translation from German, names could be different in English).
  2. Enter a title and a position on your page. I chose a unique position for every wrapper, for example iframe1.
  3. In the module’s properties, determine a URL. Unfortunately, only an absolute URL will be working. You will have to enter the complete shebang with http:// at the beginning.
  4. Save the module.
  5. In the place, where the iframe should be inserted, just use {loadposition iframe1}, where iframe1 is the position you used in step 2.
  6. Be happy! 🙂

This is working for me. Using {loadposition position} was originally introduced to include a whole module in a post, as Joomla!’s documentation specifies.

Unfortunatley, the “auto-height”-property won’t be applied properly. In my layout, I had to set the height manually. Also, it’s a bit uncomfortable to use the full URLs.

Bonus hint

If you’re including an ifram with the above mentioned method and find out that your Joomla! is including the whole page, instead of only the module’s content, try using index2.php?article&id=4 as URL instead of ../index.php?article&id=4. This should inlude only the actualy article / post, without the surrounding layout. You can definitely drop the option=com_content&view=-part of the URL-string in both variations.

Like this post? Share it!
Advertisement:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>