2

This question already has an answer here:

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"}}

.phtml:

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

marked as duplicate by Rakesh Jesadiya, Siarhey Uchukhlebau, Raphael at Digital Pianism, Amit Bera, 7ochem Feb 15 '17 at 18:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Taking refrence to This post

you can also pass array in setData function

Mage::app()->getLayout()->createBlock('products/blocks_products')
           ->setData(array('category_id'=>'12' , 'count_products'=>'4')) //for one data use setData('category_id', '12') 
           ->setTemplate('custom/list2.phtml')
           ->toHtml();

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 '17 at 9:46
  • 1
    @Prince then you can do setData('category_id', '12') – Murtuza Zabuawala Feb 15 '17 at 9:47
  • @Prince you are always welcome :) – Murtuza Zabuawala Feb 15 '17 at 9:50
4

You can try this way:

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

I haven't tested but should work.

Ref

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