I'm trying to create very simple thing - when user goes to URL http://example.com/brands/brand_name it should show a brand page that should be created based on .phtml template.

I have already added a router and successfully matched the URL:

class My_Module_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract

    public function match(Zend_Controller_Request_Http $request) 
        // let's assume that URL is http://example.com/brands/adidas

        $pageId = $request->getPathInfo(); // "brands/adidas"
        $params = trim($pageId, '/'); 
        $params = explode('/', $params); // array(brands, adidas)

        if($params[0] === 'brands') {

            // Here I need somehow to create brand page based on custom template (.phtml file that I already built)

            return true;



Please help me to understand how to tell Magento to print the template phtml file that I need.

Thank you!

  • Thanks for that. But i have an issue. I have tried the code above, when i try to reach /brands/ page a normal page with my site header and footer appear but empty, same if i try to reach /brand/ and if i try to reach /brands/adidas same. Any idea on what is wrong ? I use magento Tom
    – user2627
    Jul 9, 2013 at 15:36

1 Answer 1


You should redirect the the request to one of your controller actions. From there you can use the default Magento layout/block system to present the data you want the customer to see.
Here is what worked for me.
app/etc/modules/Easylife_Brand.xml - declaration file

<?xml version="1.0"?>
                <Mage_Core />

app/code/local/Easylife/Brand/etc/config.xml - configuration file

<?xml version="1.0"?>

app/code/local/Easylife/Brand/Controller/Router.php - custom router.

class Easylife_Brand_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract{
    public function initControllerRouters($observer){
        $front = $observer->getEvent()->getFront();
        $front->addRouter('brand', $this);
        return $this;
    public function match(Zend_Controller_Request_Http $request){
        if (!Mage::isInstalled()) {
        $pathInfo = trim($request->getPathInfo(), '/');
        $params = explode('/', $pathInfo);
        if(isset($params[0]) && $params[0] == 'brands') {
             //redirect to mymodule/brands/index/brand_name/addidas
            if (isset($params[1])){
                 $request->setParam('brand_name', $params[1]);
            return true;
        return false;

app/code/local/Easylife/Brand/controllers/IndexController.php - the controller

class Easylife_Brand_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        $brandName = $this->getRequest()->getParam('brand_name', null);
        $block = $this->getLayout()->getBlock('brands');//get the block instance
        if ($block){ //if block is valid
             if (is_null($brandName)){//if no brand name is supplied

app/design/frontend/base/default/layout/easylife_brand.xml - layout file

<?xml version="1.0"?>
        <reference name="content">
            <block type="core/template" name="brands" as="brands" />

app/design/frontend/base/default/template/easylife_brand/no_brand.html - demo template shown when no brand parameter is passes.

No brand selected:<br /><br />
List of brands:<br />
Adidas<br />
Nike<br />

app/design/frontend/base/default/template/easylife_brand/adidas.html - demo template shown when a brand parameter is passes.

<div>This is the adidas brand page.</div>

Clear the cache.
Now when I call mysite.com/brands/ I get the first template (the one with 'No brand selected'.
If I call mysite.com/brands/addidas or mysite.com/brands/something I get the second template. ('this is the adidas brand page').

  • Thank you as always for help. For some weird reason, when I add "return true;" inside that if statement (in "match" function), I receive "Front controller reached 100 router match iterations" PHP error. Otherwise if I add "return false;" - I get 404. I disabled all plugins and commented everything to be sure that other code isn't causing this, weird...
    – Marvin3
    Jun 22, 2013 at 14:28
  • I never had this issue with a custom router. Is your module called 'brands'? or something similar? Maybe the router matching is running an infinite loop.
    – Marius
    Jun 22, 2013 at 15:01
  • Nope, there is nothing even close to word "brand" in name of module. I'm including Router in the same way as this plugin does - github.com/wware-dev/store/blob/… (through event in config.xml). Maybe I should add it differently? Thank you.
    – Marvin3
    Jun 22, 2013 at 15:49
  • Seams like you are doing it right.
    – Marius
    Jun 22, 2013 at 15:55
  • I've just tested the code and I get the same result. I will update the answer when I get a solution.
    – Marius
    Jun 22, 2013 at 16:32

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.