Take the 2-minute tour ×

I am working on Magento CE 1.6.2 and would like to display 'New' Products from a specific category. To do this I have created a Static block like this and passed the category I want it from.

 {{block type="catalog/product_new" category_id="20" template="catalog/product/new.phtml"}} 

But the category Id needs to be passed dynamically from my code in one of the .phtml files. Is there a way to create a variable that I can use in this static block. Like my .phtml code is:

 $_categoryId = $this->getCurrentCategory()->getId(); //Store my category id

Can some thing be done so that I can pass this variable to my Static Block like this,

 {{block type="catalog/product_new" category_id="var $_categoryId" template="catalog/product/new.phtml"}} //Which is nothing but 20 so that it displays new products from only category 20

Please help !

EDIT: I found a link which does something similar. I tied following it but to no success. http://magentophp.blogspot.co.uk/2011/08/passing-paramters-to-magento-cms-static.html

Can any one help me follow the link and get it to working ?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

It may not be exactly what you asked for, but may point you in a right direction:

In a phtml file you can do it as such:

$category = "23";
$this->getChild('home.catalog.product.new')->setData('category_id', $category);

echo $this->getChildHtml('home.catalog.product.new', false);

note last 'false' is to tell it not to cache block.

You would need to include it in your layout file too, something like the following for your block:

<block type="catalog/product_new" name="home.catalog.product.new" alias="product_new" template="catalog/product/new.phtml"/>
share|improve this answer
Hi Alex. Thanks for your info but I'm afraid that's not exactly what I'm looking for. I have edited the question with a link that does something similar that I'm looking for. I tried to follow it but to no success. So see if you can follow that link and help me anyhow. Thanks –  ivn May 9 '12 at 16:13
That's very similar to what I was suggesting, I just split it out into the layout file too. Which bit is not as you want/not working? Do you have any other information? –  Alex Hadley May 9 '12 at 16:25

You require to put

     $this->getChild('testpage')->setData("test", "xyz")
     echo $this->getChildHtml('testpage');

Then you can call/access it by

share|improve this answer

Your Answer


