Magento: Assign Static Block to All Store's Homepages - magento

<cms_index_index>
<reference name="content">
<block type="cms/block" name="home-page-block">
<action method="setBlockId"><block_id>home-page-block</block_id></action>
</block>
</reference>
<cms_index_index>
The above code adds Static Block to Homepage, I have added a static block as per above code. But its not displayed on all stores. As All stores are using same theme.

If app/design/frontend/yourtheme/something/layout/local.xml contains:
<layout>
<cms_index_index>
<reference name="content">
<block type="cms/block" name="home-page-block">
<action method="setBlockId"><block_id>home-page-block</block_id></action>
</block>
</reference>
</cms_index_index>
</layout>
In backend I have a static block with block identified home-page-block
Its contens is displayed in all store views.

Related

Get a block type of a page Magento

I would like to know how to find the block type of some page example : the home page.
I have a problem in my homepage, I want to display some block, in the xml I declared my block in <cms_index_index> (local.xml) but if I put it in the <reference name="head"> it appears, if <reference name="content"> or <reference name="content"> it does not work . It seems to me that the type of block is not good.
xml:
<cms_index_index>
<reference name="root">
<block type="core/template" name="seconnecter_test" template="customer/form/test-seconnecter.phtml"/>
</reference>
</cms_index_index>
in the homepage 1column-full.phtml i called it like this:
<?php echo $this->getChildHtml('seconnecter_test');?>
You can use
<reference name="root">
<block type="core/template" name="seconnecter_test" output="toHtml" template="customer/form/test-seconnecter.phtml"/>
</reference>
When you give <reference name="content"> Their block type is core/text_list. this block type output their content automatically, you don't need to use getchildhtml().
In your local.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<cms_index_index>
<reference name="content">
<block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/>
</reference>
</cms_index_index>
</layout>
Place the template file at correct location, and the block will render at top of content.
Or try this go to cms->pages->homepage from admin panel. Add following in the layout update xml of design section
<reference name="content">
<block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/>
</reference>
refresh the cache.

Magento - Add a static block to the left column

How would I go about adding a static block on my left column on the category pages?
I would like the static block to go underneath the main column so that it looks like this: http://imgur.com/iopEesf
Thank-you.
override catalog.xml layout file in your template.
in and
<catalog_category_layered>
<reference name="left">
<block type="cms/block" name="block-name">
<action method="setBlockId"><block_id>block_id</block_id></action>
</block>
</reference>
</catalog_category_layered>
<catalog_category_default>
<reference name="left">
<block type="cms/block" name="block-name">
<action method="setBlockId"><block_id>block_id</block_id></action>
</block>
</reference>
</catalog_category_default>

Append custom block after addtocart button on the product view page

I try to do it by custom module xml with this code
<catalog_product_view>
<reference name="product.info">
<block type="custom/myblock" name="myblock" after="addtocart" template="custom/myblock.phtml"/>
</reference>
</catalog_product_view>
but it doesn't work. If I change the reference name to content, it goes fine, but I would like to put it after the addtocard button.
How to assign custom block there?
try this its working
<catalog_product_view>
<reference name="product.info">
<block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml">
<block type="custom/myblock" name="myblock" template="custom/myblock.phtml"/>
</block>
</reference>
</catalog_product_view>
Try this, updated block type.
<catalog_product_view>
<reference name="product.info">
<block type="core/text_list" name="myblock" after="addtocart" template="custom/myblock.phtml"/>
</reference>
</catalog_product_view>

Edit category lay-out, but apply parts to products

I've got a custom category view.phtml for this category:
http://www.touchfix.nl/onderdelen
The sub-categories use their parent's XML-update, which is:
<reference name="catalog_category_default">
<reference name="content">
<remove name="category.products" />
<block type="catalog/category_view" name="alphabase.parts" template="catalog/category/view.parts.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.parts.phtml"></block>
</block>
</reference>
</reference>
<reference name="right">
<remove name="cms_waaromkiezen" />
<block type="cms/block" name="block_speerpunten_onderdelen">
<action method="setBlockId"><block_id>block_speerpunten_onderdelen</block_id></action>
</block>
</reference>
<reference name="head">
<action method="addCss"><stylesheet>css/categoryblocks.css</stylesheet></action>
</reference>
I want to achieve that the changes to "right" are also applied to products in these categories.
But when I apply these changes to products too in category settings, the "content" reference screws up my page and it returns a blank page.
How can I reference the catalog_category view, so that the "content" update is only done when in category view and not in product view?
catalog_category_default isn't a reference, it's a handle
have you tried changing to:
<catalog_category_default>
I managed to do the trick with the following:
<reference name="content">
<reference name="category.products">
<action method="setTemplate"><template>catalog/category/view.repair.phtml</template></action>
<reference name="product_list">
<action method="setTemplate"><template>catalog/product/list.repair.phtml</template></action>
</reference>
</reference>
</reference>
<reference name="right">
<remove name="cms_waaromkiezen" />
<block type="cms/block" name="block_speerpunten_reparatie">
<action method="setBlockId"><block_id>block_speerpunten_reparatie</block_id></action>
</block>
</reference>
<reference name="head">
<action method="addCss"><stylesheet>css/categoryblocks.css</stylesheet></action>
</reference>
The difference was not to delete the blocks and add new ones with the correct template, but to change the template files of the corresponding items. I can now also refer to the product view block with <reference name="product.info">, which will be my next step.

How to remove std div in magento

I was trying to remove the "std div" from my magento home page, but unable to find the same any suggestion.
The div you are looking for is a page/html_wrapper block being added via the cms.xml layout file.
Here is the excerpt taken from app/design/frontend/base/default/layout/cms.xml:
<cms_page translate="label">
<label>CMS Pages (All)</label>
<reference name="content">
<block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
<block type="page/html_wrapper" name="cms.wrapper" translate="label">
<label>CMS Content Wrapper</label>
<action method="setElementClass"><value>std</value></action>
<block type="cms/page" name="cms_page"/>
</block>
</reference>
</cms_page>
So, there are a couple of ways to remove the div depending on how you develop your themes.
First option would be applicable if you use local.xml:
<cms_page>
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<block type="cms/page" name="cms_page"/>
</reference>
</cms_page>
Second option would be applicable if you copy the base layout files over:
Copy cms.xml from app/design/frontend/base/default/layout/cms.xml to app/design/frontend/your_package/your_theme/layout/cms.xml and edit the first layout snippet from above to the following:
<cms_page translate="label">
<label>CMS Pages (All)</label>
<reference name="content">
<block type="core/template" name="page_content_heading" template="cms/content_heading.phtml" />
<block type="cms/page" name="cms_page" />
</reference>
</cms_page>
This code helped me to remove "std" div from a single cms page,
put it to "Layout Update XML" section:
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<block type="cms/page" name="cms_page"/>
</reference>
EDIT:
Drew asked a question which makes me realize that your questions was how to remove the div (not just remove the class of the div). Ideally it's like any other "move" operation in layout XML, which means unsetting a parent-child relationship (in this case the one between the cms.wrapper and cms_page) and setting the child to another block (content):
<?xml version="1.0"?>
<layout>
<cms_page>
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<action method="insert">
<alias>cms_page</alias>
</action>
</reference>
</cms_page>
</layout>
My original response is below:
Drew has a lot of good information in his answer. I'll just point out that the block API has some nuance that can make the layout XML very clean.
In your local.xml:
<?xml version="1.0"?>
<layout>
<cms_page translate="label">
<reference name="cms.wrapper">
<action method="unsetElementClass" />
</reference>
</cms_page>
</layout>
Ref Mage_Page_Block_Html_Wrapper->_toHtml() and Varien_Object->__call()
Here is the solution you are finding :)
Put this xml code in Page -> Design -> Layout Update XML
<block type="page/html_wrapper" name="cms.wrapper" translate="label">
<label>CMS Content Wrapper</label>
<action method="setElementClass"><value>your_class_name</value></action>
<block type="cms/page" name="cms_page"/>
</block>
Cheers!
Saran

Resources