Working with JavaScript in MageBridge - Yireo

Joomla! module-positions in Magento PHTML

While the primary goal of MageBridge is to have Magento blocks being displayed in Joomla! - and thus, wrap the Magento theme within the Joomla! template - there are more tricks to add Joomla! module-positions to the Magento theme as well. So, MageBridge not allows you to integrate Magento parts in Joomla!, but also Joomla! parts in Magento.

Joomla! module-positions in PHTML-templates

Within Joomla!, you can add jdoc-tags to your Joomla! template to add-in module-positions. The same jdoc-tags can be added to Magento PHTML-templates, as long as those Magento PHTML-templates are transferred to Joomla! and parsed by MageBridge. For this to work, within the Joomla! component of MageBridge, the option Enable JDoc-tags needs to be enabled.

Adding module-positions is then easy: Copy a Magento PHTML-file to your own Magento theming directory (following the guidelines of Magento), open it up and add the jdoc-tag to the code. This jdoc-tag doesn't do anything in Magento, but is translated by Joomla! when it arrives in Joomla!.

<jdoc:include type="modules" name="right" />

This will insert all Joomla! modules assigned to the position right in this Magento PHTML-template. Make sure that the Joomla! modules are assigned to All Pages, because Joomla! page assignment doesn't do much on the various pages of Magento/MageBridge. As a best practice, it is a good idea to use specific Joomla! module-positions for use within these PHTML-templates (for instance phtml-checkout-top or magebridge-cart-banner).

Once you get the hang of this, you will find this a very powerful feature.

Adding Joomla! module-positions through XML-layout

As an alternative, you can also add module-positions through Magento XML-layout code. Within the layout, a MageBridge block of type magebridge/position is instantiated and its output is actually generating again a jdoc-tag, which is then translated by Joomla! when the Magento block is sent to Joomla!.

<block type="magebridge/position" name="magebridge-right">
<action method="setPosition"><string>mb-right</string></action>
</block> 

When the setPosition-method is left out, the original layout-name is used (in the example above: magebridge-right)

Optionally you can also set a module-style (just like you would with jdoc-tags) through the following method:

<action method="setStyle"><string>xhtml</string></action>

Adding Joomla! module-positions in the standalone Magento frontend

MageBridge is normally called through the Joomla! application, in other words when Magento blocks are translated into Joomla! content. But when Magento is called directly, the MageBridge connection is not active and jdoc-tags are pointless. However, the MageBridge API can still be called, and this is one of the cases:

When the XML-layout code is active in the Magento theme, and a block magebridge/position is called, MageBridge will use the API to fetch all module-output from Joomla! through JSON-RPC. Note that this is only useful when you still use the separate Magento frontend (instead of the MageBridge frontend in Joomla!) and is therefor less preferred (but still possibe).

Created on Thursday, 13 October 2011
Modified on Thursday, 13 October 2011

About Yireo

Yireo tries to help webdevelopers build successful Joomla! and Magento sites.

More about Yireo