Yireo tutorials

Learn more about Joomla!TM and Magento
You are here: Home Tutorials MageBridge MageBridge theming MageBridge template helper

MageBridge template helper

Integrating a Magento theme into Joomla! is not as straight forward as it seems. MagentoTM blocks are only shown on certain MageBridge pages, while Joomla! does not know how to handle empty bodies of Joomla! modules. Also, assigning a Joomla!TM module to certain MageBridgeTM pages is impossible because the Joomla! Menu Assignment is just not flexible enough.

The best solution for all these problems is to add PHP-code to the template. But because Joomla! still does not know about the Magento theming logic, the MageBridge template helper-class MageBridgeTemplateHelper allows you to configure things while using fairly simple PHP-code.

Adding PHP-code to your Joomla! template

Knowledge of HTML and CSS is nice to change the visual appearance of a Joomla! template, but as soon as you are dealing with logical decisions like hiding certain columns on certain pages, PHP-knowledge is needed. Guides for Joomla! templating are full with examples like the following:

 
<?php if($this->countModules('left')) : ?>
<div id="left">
<jdoc:include type="module" name="left" style="xhtml" />
</div>
<?php endif; ?>
 

This checks if the module-position "left" contains any module-instances, because if there are no modules to be shown, the left column need not to appear.

We can extend this example by saying that the left-column should only appear if there are modules available on the position "left", but also if the current page is not the homepage. This practically hides the left-column on the homepage:

 
<?php
$menu = JSite::getMenu();
$active = $menu->getActive();
$homepage = (boolean)$active->home;
?>
...
<?php if( $homepage == false && $this->countModules('left') ) { ?>
<div id="left">
<jdoc:include type="module" name="left" style="xhtml" />
</div>
<?php } ?>
 

As you can see: The more logic you want in your template, the more complex the PHP-code becomes.

Adding Magento logic to your template

The same applies with MageBridge: When you add the Magento theme to Joomla!, two theming mechanisms are integrated. But if you want the integration to become seamless, you either need to extend Magento with Joomla! templating logic, or add Magento theming logic to Joomla!. We have choosen for the last option.

The PHP-class MageBridgeTemplateHelper (which can be found in the folder components/com_magebridge/helpers/template.php) helps you with simple tasks, like determining if the current page is the Magento homepage or not:

 
<?php if( MageBridgeTemplateHelper::isHomePage() == true ) { ?>
...
<?php } ?>
 

Because the Magento theming engine also adds different page-layouts, these page-layouts might also be needed to determine whether a column in Joomla! should be shown or not:

 
<?php if( MageBridgeTemplateHelper::hasLeftColumn() && $this->countModules('left')) { ?>
...
<?php } ?>
 

As you can see, with this new logic the Joomla! templating engine is enhanced tremendously by adding extra MageBridge logic. However, if things are more flexible, they are also more complex: This is for the more advanced webdesigners.

MageBridgeTemplateHelper methods

While the PHP-code of the MageBridgeTemplateHelper class is simple and straight-forward (components/com_magebridge/helpers/template.php), here is an overview of the current methods anyway:

Method Argument Return Description
hasCss   true|false Determine if the bridge is loaded with some CSS-stylesheets
hasJs   true|false Determine if the bridge is loaded with some JavaScript-scripts
getRootTemplate   true|false Get the current page layout
getPageLayout   string Alternative for getRootTeplate
hasLeftColumn   true|false Determine if the Magento theme is using the left-column layout
hasRightColumn   true|false Determine if the Magento theme is using the right-column layout
hasAllColumns   true|false Determine if the Magento layout uses all three columns (main component plus left plus right)
hasTwoColumns   true|false Determine if the Magento layout uses two columns (main component plus one side-column)
hasOneColumn   true|false Determine if the Magento layout uses only one column (main component)
getRequest   string Get the current Magento page-request
isHomePage   true|false Determine if the current request is the homepage
isPage string true|false Determine if the current request is a specific page
isCatalogPage   true|false Determine if the current request is a catalog page
isProductPage   true|false Determine if the current request is a catalog product page
isCategoryPage   true|false Determine if the current request is a catalog category page
isCustomerPage   true|false Determine if the current request is a customer page
isCheckoutPage   true|false Determine if the current request is a customer page

Skipping empty modules

Within a Joomla! template you can check with the code $this->countModules('left') if there are any modules available on the left. If you put some MageBridge modules (containing Magento blocks) on the module-position "left", this works without a problem. But if the Magento blocks are empty, you actually want to hide the modules. The first step into dealing with this, is to setup the right module-chrome (see MageBridge and module chromes).

But if all the modules on the position "left" are empty, you actually want to hide the entire left-column. Unfortunately, the Joomla! "countModules" method is not smart enough to detect empty modules (though it is a feature which has been discussed for Joomla! 1.6). The MageBridgeTemplateHelper-class offers an alternative which allows you to hide the left-column if it is empty.

 
<?php if( MageBridgeTemplateHelper::countModules('left')) { ?>
...
<?php } ?>
 

Checking for any Magento page

While the MageBridgeTemplateHelper class offers various shortcuts for determining which page you are on, the isPage method allows you to determine any page. The benefit of using this method, instead of using an uglier method like $_SERVER['REQUEST_URI'], is that the Magento SEO URLs are translated back to their original non-SEF URL.

To determine if the current page is the wishlist page:

 
<?php if( MageBridgeTemplateHelper::isPage('wishlist/*')) { ?>
...
<?php } ?>
 

The argument wishlist/* is handed over to the isPage method and is used as a simple regular expression. If you wanted to check for a single product page, the argument would be catalog/product/view/*.

Instead of working with the abstract MageBridgeTemplateHelper::X() methods, you can also instantiate the helper and use a shorter variable-name instead:/p>

 
<?php
$mb = new MageBridgeTemplateHelper();
?>
...
<?php if( $mb->isPage('wishlist/*')) { ?>
...
<?php } ?>
 

Tutorials on MageBridge theming

Tutorials on MageBridge development

 

Payments Methods

Payment Methods