magento CE v1.6 toplinks in static block - magento

I would like to have the topLinks within Magento CE 1.6 displayed within a static block. This is due to the fact that my site is running four different stores [multi-store - different domains] and need to have topLinks on only two stores, whilst using one template.
I did try to convert the php call [getChildHtml('topLinks'); ?>] into a block tag within the static block but was not successful. Have looked in depth at the xml for the template_links [made from varied xmls] but could not come to terms as how to just make a {{block}} within the static block to display the topLinks.
The call for the static block is in place, just need help achieving the topLinks within.
Any help will be appreciated.
With best regards
Fab
A fine tune of my question:
Basically I need to amend the page.xml
from
<block type="page/template_links" name="top.links" as="topLinks"/>
to
<layout>
<static_block_top_links>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
<block type="cms/block" before="-" name="some_name" as="topLinks">
<action method="setBlockId">
<name>some_static_block</name>
</action>
</block>
</reference>
</static_block_top_links>
<STORE_store>
<update handle="static_block_top_links" />
</STORE_store>
<STORE_law>
<update handle="static_block_top_links" />
</STORE_law>

Use local.xml to implement your changes:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="header">
<!-- Unset original toplinks block -->
<action method="unsetChild">
<name>topLinks</name>
</action>
<!-- Add static block in place with same alias -->
<block type="cms/block" before="-" name="some_name" as="topLinks">
<action method="setBlockId">
<name>some_static_block</name>
</action>
</block>
</reference>
</default>
</layout>
Please note that 'some_name' can be anything except for 'top.links', as that would cause several things in core XML files to try and perform actions on your cms block.
In response to your edit, you can easily do it for only some stores like so:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<static_block_top_links>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
<block type="cms/block" before="-" name="some_name" as="topLinks">
<action method="setBlockId">
<name>some_static_block</name>
</action>
</block>
</reference>
</static_block_top_links>
<STORE_myfirststore>
<update handle="static_block_top_links" />
</STORE_myfirststore>
<STORE_mysecondstore>
<update handle="static_block_top_links" />
</STORE_mysecondstore>
</layout>

Hello for anyone of you having a magento CE 1.6+ multi-store multi-domain and would like to remove the topLinks in general for certain stores, this is the correct method.
Create a local.xml in your app/design/frontend/default/yourtheme/layout/
Your local.xml should be like this
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<STORE_mystore1>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
</reference>
</STORE_mystore1>
<STORE_mystore2>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
</reference>
</STORE_mystore2>
</layout>
Replace the mystore1 and mystore2 with the code under Store View [Admin -> Manage Stores -> Store View Name -> Code]
Make sure that you encode the layout.xml in UTF-8
Upload the layout.xml in the app/design/frontend/default/yourtheme/layout/ folder.
Refresh the cache.
I would like to thank Daniel Sloof and Robert Popovic for their input.

Related

How to remove the side bar cart from all pages but keep on product listing page in magento using local.xml

I have following code in local.xml
<default>
<remove name="cart_sidebar" />
</default>
To remove the sidebar cart from all pages but I want to keep it on product listing page and product details page.
How can I do this?
To achieve this you need to use Unset / Remove method.
To move a child block from one parent to another, reference the direct parent, call unsetChild on it, and then use the insert/add block method to assign the block instance as child to a different parent.
Try below code in your local.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<default>
<reference name="right">
<action method="unsetChild"><name>cart_sidebar</name></action>
</reference>
</default>
<!--If you are not using layered navigation code start -->
<catalog_category_default>
<reference name="right">
<action method="insert"><block>cart_sidebar</block></action>
</reference>
</catalog_category_default>
<!--If you are not using layered navigation code end -->
<!--If you are using layered navigation code start -->
<catalog_category_layered>
<reference name="right">
<action method="insert"><block>cart_sidebar</block></action>
</reference>
</catalog_category_layered>
<!--If you are using layered navigation code end -->
<catalog_product_view>
<reference name="right">
<action method="insert"><block>cart_sidebar</block></action>
</reference>
</catalog_product_view>
</layout>

What is preventing my layout updates from being displayed

I am trying to display a simple message on my Magento site using a special block that I have created. I have been able to easily unset blocks and insert them in other places on the home page, but I am running into trouble when I try to do the same thing on one of the product pages. I have created a file at app/design/frontend/base/default/layout/packagename/modulename.xml
with the following contents:
<?xml version="1.0"?>
<layout>
<default>
<reference name="product.info">
<block type="core/text" name="free_shipping">
<action method="setText"><text><![CDATA[<div>Free Shipping!</div>]]> </text></action>
</block>
</reference>
<reference name="header">
<action method="unsetChild">
<name>top.search</name>
</action>
</reference>
</default>
</layout>
It seems to me like the code above would remove the search bar from a product page and add a block in the product info section that says "Free shipping!" but when I load the page there are no changes. I have tried using "remove" to alter some of the blocks on the page and it works, so the file is definitely being loaded into the layout.xml. I have also tried making my changes in the local.xml file instead, with the same results. Other than that, I am kind of at a loss for things to try to get this to work correctly.
Edit: To provide some more information on the problem, if I were to replace my changes with something like
<reference name="root">
<action method="unsetChild">
<name>header</name>
</action>
</reference>
The header is sucessfully removed. So I guess the question now is, why does calling unset child work as expected when used on the "root" block but not on "header"?
I think you need to be more specific with your layout handler, you are setting it as and that means all pages, i recommend you change that handler by
<?xml version="1.0"?>
<layout>
<catalog_product_view>
<reference name="product.info">
<block type="core/text" name="free_shipping">
<action method="setText"><text><![CDATA[<div>Free Shipping!</div>]]> </text></action>
</block>
</reference>
<reference name="product.info">
<block name="header">
<action method="unsetChild">
<name>top.search</name>
</action>
</block>
</reference>
</catalog_product_view>
</layout>
Greetings.
First of all, never put your stuff in the base/default folder.
On to your question. What if you try it like this:
<reference name="header">
<action method="unsetChild">
<name>top.search</name>
</action>
</reference>
To answer your other question:
The header is sucessfully removed. So I guess the question now is, why does calling unset child work as expected when used on the "root" block but not on "header"?
It's not the fact it's on the root block, it's that you should use unsetChild within the <reference/> part.

Override Magento Template

I'm making a module that needs to override the block/template for the top.phtml so I add in the layout of my module this code.
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<default translate="label" module="page">
<reference name="top.menu">
<action method="setTemplate"><template>navigationmenu/navigationMenu.phtml</template></action>
</reference>
</default>
</layout>
It doesn't work, but If I try to reference the header block it changes the template, I don't know if i have to set anything else in my xml.
Edit:
This is the structure in page.xml
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
<block type="page/html_header" name="header" as="header">
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
</block>
</block>
</block>
I realize I don't need the setTemplate because I need to use my custom Block
It is ok to put my reference under the default tag? Do I need to make another reference?
Also I'm running Magento EE 1.9.1.1 if that helps

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

Magento product display grid columns on home page

Trying to get the home page to display a 4 column grid for the display of items using a two_column_right template, in the local.xml file. Unfortunately it's taking on the three column grid I've specified for catalog pages elsewhere :/
Possibly need to insert <update handle="four_column_grid" /> under a tag referencing the home page??
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<four_column_grid>
<reference name="product_list">
<action method="setColumnCount">
<count>4</count>
</action>
</reference>
</four_column_grid>
<three_column_grid>
<reference name="product_list">
<action method="setColumnCount">
<count>3</count>
</action>
</reference>
</three_column_grid>
<default>
<!-- Header -->
<reference name="header">
<action method="unsetChild"><name>welcome</name></action>
</reference>
<!-- Root -->
<reference name="root">
<action method="unsetChild"><name>breadcrumbs</name></action>
</reference>
<reference name="footer">
<!-- Remove all the other Magento links - "Site Map, Search Terms, Advanced Search, and Contact Us" -->
<!-- <action method="unsetChild"><name>footer_links</name></action> -->
</reference>
<!-- Right sidebar -->
<reference name="right">
<remove name="paypal.partner.right.logo"/>
</reference>
</default>
<catalog_category_default>
<update handle="three_column_grid" />
</catalog_category_default>
<catalog_category_layered>
<update handle="three_column_grid" />
</catalog_category_layered>
</layout>
Short answer: you can't set values on blocks "inside" of CMS blocks using layout XML.
When loadLayout() is called in action controllers, the layout XML is processed, all blocks are instantiated, and the <action> nodes are executed. But the blocks are not yet rendered.
When renderLayout() is called the blocks are rendered by calling their toHtml() method.
If the block happens to be a cms/block (or cms/page) instance containing a {{block ...}} instance, that block will be instantiated at this time.
At this moment during the request flow all layout XML <action> nodes already have been processed.
In essence you are referencing a block instance in the layout XML that doesn't yet exist.
As a workaround, it might work for you to add the product list block to the homepage using layout XML, too. The downside is that you can't place it freely in other content of the CMS block.
<cms_index_index><!-- layout handle for the default homepage action -->
<reference name="content">
<block type="catalog/product_list" name="product_list">
<action method="setTemplate">
<template>catalog/product/list.phtml</template>
</action>
<action method="setCategoryId">
<catId>51</catId>
</action>
<action method="setColumnCount">
<count>4</count>
</action>
</block>
</reference>
</cms_index_index>
Of course you are not limited to the product list block. If you need to place the list inside of other content, you could add cms blocks to the homepage using layout XML ad well.
Note that this seems to have changed in magento ce 1.9+ when extending the rwd theme. You'll have to define to more blocks for 'name.after' and 'after'.
<cms_index_index>
<reference name="content">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="core/text_list" name="product_list.name.after" as="name.after" />
<block type="core/text_list" name="product_list.after" as="after" />
<action method="setCategoryId"><catId>3</catId></action>
<action method="setColumnCount"><count>4</count></action>
</block>
</reference>
</cms_index_index>

Resources