Magento: call dynamic widget block id in .phtml file

Well, here's what I'm trying to do, I read a ton of links and posts, but it seems like I'm trying to do, it's a little different.

I have several static blocks on my homepage, 1 advertising rotator, 1 slider that displays products defined in the product category, and finally another category that currently points to a static category, but does the same thing and recognized.

My task is to randomize this last category, I was able to achieve this by writing my own .phtml file and looping through the mt_rand of several static blocks already created.

This, however, goes one step deeper, what I want to do is have one static block and have a random category identifier, here is an example:

{{block type="catalog/product_list" category_id="392" template="catalog/product/home-list.phtml"}} 

Now, using this concept, I tried to try to create another .phtml file and call a static call to the .html block, which is something like this:

 <?php $input = array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150); $rand_keys = array_rand($input, 2); echo "{{block type=\"catalog/product_list\" category_id=\"{$input[$rand_keys[0]]}\" template=\"catalog/product/home-list.phtml\"}}"; ?> 

Now this example really does the job, I can load an array from what I ever wanted for me to search for a category, and just scroll it randomly or most.

Where my real problem comes into play is that printing this information on the screen does not affect what I was hoping for, what it does is just printing the text, and although every screen update gives me a new random element of the ID array wise, its just text on the screen.

If someone can help me solve this problem and be able to get the text translated into the working tag of the widget, which would be fantastic, because I did a lot of research and met deadlocks every time.

Thanks in advance,

Hooray!

+4
source share
1 answer

You need a slightly different syntax for use in views. Some pseudo examples

 echo $this->getLayout()->createBlock('catalog/product_list')->setTemplate('catalog/product/home-list.phtml')->setCategoryId('392')->toHtml(); 

or if the block already exists in the layout, you can get it by name:

 echo $this->getLayout()->getBlock('blockname')->setTemplate('catalog/product/home-list.phtml')->setCategoryId('392')->toHtml(); 
+5
source

All Articles