Updating custom block in CMS page - magento

I'm having a bit of trouble understanding how to update a custom block that I include in a CMS page.
I am using the standard shortcode in the CMS page, which works fine:
{{block type="catalog/product_list" category_id="16"
template="catalog/product/slider_list.phtml"}}
I am trying to set the column count of this custom custom block, for which I've found that I need something like the following piece of code:
<block type="catalog/product_list" name="catalog.product.slider_list"
template="catalog/product/slider_list.phtml">
<action method="setColumnCount"><columns>4</columns></action>
</block>
I'm not exactly sure under which <reference /> block I should place the code... I looked in catalog.xml, and if I try to place it between <reference name="root" />, I do not get the correct behavior.
Thank you.
Edit: use of incorrect terminology; I was calling the block static, where in fact it is a custom block.

if you want to call it on home page where the reference name should be like in your local.xml or any of the xml of your extension. just add it like below
<cms_index_index>
<reference name="content">
// your custom block
<block type="catalog/product_list" name="catalog.product.slider_list"
template="catalog/product/slider_list.phtml">
<action method="setColumnCount"><columns>4</columns></action>
</block>
</reference>
</cms_index_index>
hope this will sure help you.

Related

cart.phtml override issue

I am trying to override cart.phtml from checkout\cart.phtml using local.xml
<layout version="0.1.0">
<checkout_cart_index translate="label">
<reference name="checkout.cart">
<action method="setTemplate"><template>test/cart.phtml</template></action>
</reference>
</checkout_cart_index>
</layout>
override works fine but when i try to empty cart it always call my cart.phtml instead of checkout\cart\noItems.phtml.
when my cart is empty then it looks like
Any help will be appreciated
Thank you
Take a look at the original checkout.xml
<block type="checkout/cart" name="checkout.cart">
<action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
<action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
It has 2 template methods - setCartTemplate and setEmptyTemplate. Add these methods and you should be golden.
The chosen answer by PixieMedia will not work as is. It is missing the essential method call: chooseTemplate. Without it the answer will not work. Read https://stackoverflow.com/a/33875491/2973534 for a thorough explanation; that post contains the proper answer.

Magento creating CMS blocks from xml block

<reference name="left">
<!-- Layered Navigation Block -->
<block type="catalog/layer_view" name="catalog.leftnav" template="catalog/layer/view.phtml" >
<action method="setCategoryId"><category_id>2</category_id></action>
</block>
</reference>
I was able to create a CMS block from the above code
{{block type="catalog/layer_view" category_id="2" name="catalog.leftnav" template="catalog/layer/view.phtml"}}
How would I create a CMS block from the XML below...it have a bit more to it.
<reference name="content">
<block type="catalog/product_list" name="home" template="catalog/product/list.phtml">
<!-- Product List View -->
<action method="setCategoryId"><category_id>2</category_id></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
Unfortunately you cannot do what you need.
Here is why. When using the {{block}} directive magento automatically calls toHtml after creating the block and returns you the html (rendered block).
This directive also does not support blocks inside blocks.
When working with layout files, the blocks are not rendered automatically. First the layout file is parsed, the block classes are instantiated, they are assigned as child blocks or parent blocks and everything is rendered at the end.
In your case you will need something like this:
{{block type="catalog/product_list" template="catalog/product/list.phtml" name="home" toolbar_block_name="product_list_toolbar"}}
But this won't work because the block with the name product_list_toolbar does not exist yet.
If you try to create it before with something like this:
{{block type="catalog/product_list_toolbar"....}}
still won't work, because the block will just be outputed (most probably you will get an error too).
Blocks generated using {{block}} are not added to the layout so they cannot be referenced in other blocks.

To add product grid in custom module admin form

I have created custom module in magento. Its working good. But now my problem is, I want to add product grid to my product list tab.I have found the solution through this link.I have created new tab.But when i load that tab, its shows me an error like
Fatal error: Call to a member function setProdlist() on a non-object in /home/trendyc/public_html/app/code/community/Whole/Cate/controllers/Adminhtml/WhcatalogController.php on line 64
Mycontroller file's productsAction code here
$this->getLayout()->getBlock('products.grid')
->setProdlist($this->getRequest()->getPost('products_prodlist', null));
I think, i need to do some modification on layout file. But i can't get what modifications need to do there in layout .xml file.I hope you understand my problem. Please help me guys!
You should create xml for your extension, for ex. design/adminhtml/default/default/layout/my_ext.xml and describe your block product.list
<ext_adminhtml_item_products>
<block type="core/text_list" name="root" output="toHtml">
<block type="ext/adminhtml_item_edit_tab_products" name="products.grid"/>
<block type="adminhtml/widget_grid_serializer" name="products_grid_serializer">
<reference name="products_grid_serializer">
<action method="initSerializerBlock">
<grid_block_name>products.grid</grid_block_name>
<data_callback>getSelectedProducts</data_callback>
<hidden_input_name>links[prodlist]</hidden_input_name>
<reload_param_name>products_prodlist</reload_param_name>
</action>
</reference>
</block>
</block>
</ext_adminhtml_item_products>
you can use this on cms page:
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}
or in phtml use this to display products:
$this->getLayout() ->getBlockSingleton('ccatalog/product_list')->setTemplate('catalog/product/list.phtml')->toHtml();

Magento Block Placement

I want to add the block section below on the product detail section
currently its above
as shown in below image
does any one knows this?
my layout is
1st for facebook comment
<reference name="product.info">
<block type="facebookcomments/catalog_product_comments" name="product.info.facebookcomments" template="facebookcomments/catalog/product/comments.phtml"/>
2nd is for facebook like
<reference name="product.info">
<block type="facebookilike/catalog_product_facebookilike" name="product.info.facebookilike" template="facebookilike/catalog/product/facebookilike.phtml"/>
still not getting this
In catalog_product_view handle of your theme/module layout:
(note i'm pseudo-coding based on the debug block names in your screenshot. I may not have the correct block/template/handles, but you get the idea)
<reference name="content">
<block type="mageplace_facebook/like_catalog_product_facebooklike"
after="product.info"
name="facebook.like.block.name"
template="path/to/facebooklike/template.phtml" />
</reference>
Check the layout xml of the Facebook Comments module, as it's obviously in the right place.

Magento: Change the block template in local.xml

I would like the product reviews page to use a different template instead of:
catalog/product/view.phtml
In review.xml, I see the file being called:
<block type="review/product_view" name="product.info" template="catalog/product/view.phtml">
Is there a way I can override that in local.xml and create a new file (ex: view2.phtml) and use that for this page?
<review_product_list>
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/view2.phtml</template></action>
</reference>
</review_product_list>
Yes, you can definitely do that by writing the following code in local.xml:-
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/view2.phtml</template></action>
</reference>
Here view2.phtml is your new file in the proper folder structure.
Hope it helps.

Resources