I have some block in CMS page, I want to move it in .phtml file, but I don't know how to parse these variables(category_id="12", count_products="4"), and from where these variables are coming? from a block right ?

CMS block:

{{block type="products/blocks_products" category_id="12" count_products="4" template="custom/list2.phtml"}}


<?php echo Mage::app()->getLayout()->createBlock('products/blocks_products')->setTemplate('custom/list2.phtml')->toHtml(); ?>

2 Answers 2


Taking refrence to This post

you can also pass array in setData function

           ->setData(array('category_id'=>'12' , 'count_products'=>'4')) //for one data use setData('category_id', '12') 

Supposing that if you have just one variable,then no need to put array, Just use setData('category_id', '12')

  • supposing that I have just one variable, I will put it in an array ? setData(array('category_id'=>'12'))
    – PЯINCƎ
    Feb 15, 2017 at 9:46
  • 1
    @Prince then you can do setData('category_id', '12') Feb 15, 2017 at 9:47
  • @Prince you are always welcome :) Feb 15, 2017 at 9:50

You can try this way:

<?php echo Mage::app()->getLayout()->createBlock('products/blocks_products')
    ->setTemplate('custom/list2.phtml')->toHtml(); ?>

I haven't tested but should work.


Not the answer you're looking for? Browse other questions tagged or ask your own question.