5

This code gives me a bunch of products:

 {{block type="catalog/product_list" limit="4" category_id="13" template="catalog/product/list.phtml"}}

This code gives me nothing:

 {{widget type="catalog/product_list" limit="4" category_id="13" template="catalog/product/list.phtml"}}

Why does the "block" version work out of the box and the widget code does not?

  • I would like to add more to the existing answers based on my understanding, Block contains info e.g. text/images and has no logic and cannot reference/display itself. A widget is more like a container that can carry and display Blocks. – Mohammed Joraid Feb 25 '18 at 0:53
1

As far as the concept i understood...

A widget is somehow similar to a static block but not exactly.

As a concept, a widget is a unique key (widget type) that maps to some code, and a set of parameters used by that code.

(A widget is a snippet of code that makes it possible to display a wide range of content and place it at specific block references in your store. Many widgets display real-time, dynamic data and create opportunities for your customers to interact with your store. The Widget tool makes it easy to place existing content such as static blocks with images and text, and interactive elements most anywhere in your store.)

These way you can add a widget in .phtml file

<?php
$filter = Mage::getModel('widget/template_filter');
echo $filter->filter('{{widget type="cms/widget_page_link" template="cms/widget/link/link_block.phtml" page_id="2"}}');
?>

A static block is actually some text that can contain other elements (like widgets).

The difference between them from Magento's point of view is that you can place different widgets in different sections of different pages using the backend UI. The static blocks can only be placed in fewer page types and sections.

Static blocks can contain widgets and the other way around.

  • Thanks, but I think what I'm looking for is what Magento sees as different when it compiles those two lines. They both indicate a type so there is a path to the code that is supposed to execute. I don't see why Magento doesn't produce anything all for the widget code yet it has built-in instructions for how to handle a block. Isn't there some basic behavior for a widget? If not, how do the attributes defined here direct it to the underlying code? – jmargolisvt Aug 14 '16 at 19:59
1

Widgets:

  • small applets/components, that means it has behavior, logic, and/or side-effects.
  • can contain a block widget (a small script that renders a block).
  • fixed based on type; cannot have custom content.

Blocks:

  • Have no logic.
  • flexible containers, used to display text, child blocks or widgets.
  • provide a bridge for config, layout for its views/components.

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.