Magento Block Positioning Never Works - magento

Hello I always seem to have problems positions blocks.
Please see the website I am working on: http://www.hemptationz.com
I want the blocks on the left sidebar to appear in this order:
Facebook Block (callouts/facebook.pthml)
Currency Block (directory/currency.phtml)
Product Categories Block (vertnav/left.phtml)
Information Links Block (callouts/left_col.phtml)
This is the code I have in the XML layout files:
Catalog.xml
<reference name="left">
<block type="core/template" name="facebook" template="callouts/facebook.phtml" after="currency" />
<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml" after="catalog.vertnav" />
</reference>
vertnav.xml
<reference name="left">
<block type="vertnav/navigation" name="catalog.vertnav" template="vertnav/left.phtml" before="left.permanent.callout" />
</reference>
directory.xml
<layout version="0.1.0">
<!--
Category default layout
-->
<default>
<reference name="head">
<block type="core/template" name="optional_zip_countries" as="optional_zip_countries" template="directory/js/optional_zip_countries.phtml" />
</reference>
</default>
<catalog_category_default>
<reference name="left">
<block type="directory/currency" name="currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalog_category_default>
<!--
Category layered navigation layout
-->
<catalog_category_layered>
<reference name="left">
<block type="directory/currency" name="currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalog_category_layered>
<!--
Catalog Search layout
-->
<catalogsearch_advanced_index>
<reference name="left">
<block type="directory/currency" name="right_currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalogsearch_advanced_index>
<catalogsearch_result_index>
<reference name="left">
<block type="directory/currency" name="currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalogsearch_result_index>
<catalogsearch_advanced_result>
<reference name="right">
<block type="directory/currency" name="right_currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalogsearch_advanced_result>
</layout>
Thanks hope you can help me.

The before and after attributes are limited in scope. They can only influence
The order of blocks within a particular sub-block when that sub-block is a core/test_list or other block that automatically renders sorted children.
You've not given enough context around how you're using the attributes in your question to give you specific advice, but I don't think you can do what you think you can with the feature. Be more explicit in your question and provide code example, along with "I expected foo, I got bar" style context, and will help you.

You want this order:
1. Facebook
2. Currency
3. Vertical Navigation
4. Information Links
but in your layout you have specified that facebook is after currency. If you want something to show first you have to use before="-" (in facebook link), then use after="facebook" for currency, after="currency" for catalog.vertnav and use after="-" for left.permanent.callout to position it on the bottom.

Related

MAGENTO SIDEBAR BLOCK NOT SHOW

I had a three block on my left sidebar.
when I am calling this three block as shown below, it shows only last block. First and second blocks are not showing
<reference name="left">
<remove name="catalog.leftnav" />
<block type="catalog/navigation" before="-"name="left-nav-brand" template="catalog/product/brand_sidebar.phtml"></block>
<block type="cms/block" name="left-nav">
<action method="setBlockId">
<block_id>left-nav</block_id>
</action>
</block>
<block type="catalog/product_list" name="catalog.product.latest" template="catalog/product/latest.phtml"></block>
</reference>
What would be the possible cause ?

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

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>

currency selector updating in local.xml

I want to keep the currency selector in top. So i added this code in local.xml:
<default>
<reference name="header">
<block type="directory/currency" name="currency" before="catalog.leftnav" template="directory/currency.phtml"/>
</reference>
</default>
Now how can i remove currency selector from left, right position. I tried this:
<default>
<reference name="left">
<remove name="currency"/>
</reference>
</default>
It removes all currency selector!
You named your header block currency as well. I would try renaming that header block (try header.currency) and see if that does it for you.
To remove from search results left side bar I used this:
Commet this out from directory.xml
<catalogsearch_result_index>
<reference name="left">
<block type="directory/currency" name="currency" before="-" template="directory/currency.phtml"/>
</reference>
</catalogsearch_result_index>
<remove name="currency"/>
Removes curreny module.If you want to remove currency from left sidebar and use it somewhere,code must be
<default>
<reference name="left">
<action method="unsetChild"><name>currency</name></action>
</reference>
</default>

Resources