Magento Sidebar Customization - magento

I have a magento website, of which Ive customized the rightside bar static block fine.
It displays as it should on all pages except the product pages.
Is this something that needs editing in the layout xml files, within the magento control panel or within other design files?
Thanks!
update:
The problem is that the global right sidebar is displaying everything as it should, however the product page is still displaying the old version, without the amends.

You simply need to add the product view xml updates to your local.xml layout file (or create it). The file would be located at:
/app/design/frontend/your_package/your_theme/layout/local.xml
An abridged version of the xml you would need is:
<?xml version="1.0"?>
<layout version="0.1.0">
<!-- Layout Handle for Product View Page -->
<catalog_product_view>
<!-- Reference Pointing to Right Sidebar -->
<reference name="right">
<!-- Enter All Right Sidebar Layout Updates Here -->
</reference>
</catalog_product_view>
</layout>
If you renamed your right sidebar something else, change the reference name above to what you changed it to. Here's some quick references to show what you can do to arrange via local.xml:
Move or Remove Blocks
<reference name="right">
<!-- Removes Block By Name -->
<remove name="name_of_removed_block"/>
<!-- Insert Moved Block (Must Unset First, See Left Reference) -->
<action method="insert">
<blockName>name_of_unset_block</blockName>
<siblingName>name_of_adjacent_block</siblingName>
<after>1</after> <!-- 0 = Before / 1 = After Sibling Block -->
</action>
</reference>
<reference name="left">
<!-- Unset Block By Name, Can Be Inserted Elsewhere As Above -->
<action method="unsetChild">
<name>name_of_unset_block</name>
</action>
</reference>
Add A Block From a Template File
<!-- Blocks Left and Right Automatically Load All Child Html -->
<reference name="right">
<!-- Load New Block From Template File -->
<block type="core/template" name="new_block_name" template="page/html/newblock.phtml" after="adjacent_block_name" />
</reference>
<!-- Some Blocks (Like Header) Require Child Html to be Called After Set in XML -->
<reference name="header">
<!-- Adding a Block Below Won't Be Enough To Add Our Template File Here -->
<block type="core/template" name="new_header_block" template="page/html/headerblock.phtml" />
</reference>
Not all blocks added will show immediately, sometimes you need to go within the parent block's template file to add the child block where you would like. In the above example, I used the "header" block, for anything to actually be added I have to edit the .phtml file directly. (unless you have changed your header.phtml to only use $this->getChildHtml(''); as no block name indicates that Magento should load all child html blocks.)
In this case, we would have to make a change to header.phtml, and somewhere within that file (/app/design/frontend/your_package/your_theme/page/html/header.phtml) you would need to add:
<?php echo $this->getChildHtml('new_header_block'); ?>
Where you would like to see your block added to the header.
That should get you started in the right direction. Make sure that none of your pages/products/categories have any custom layout xml in their records on the backend that may be affecting what shows up on the front as well.

Related

How to hide a custom block on checkout Magento

I need to hide a custom block on all checkouts (onepage and cart).
How should I edit the checkout.xml to hide it?
I tried <remove name="footer_newsletter"/> but it doesn't work. The strange thing is that if I put <remove name="footer" /> all the footer is hidden.
So where is the problem? On blocks section the ID and name is footer_newsletter so it's not wrong.
First remove the changes you have done on checkout.xml for Add local.xml to your theme layout folder.
For example in default magento theme it would be in app/design/frontend/default/default/layout
To your theme's layout folder add local.xml. In this local.xml Write following code:
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_cart_index>
<reference name="footer">
<remove name="footer_newsletter"/>
</reference>
</checkout_cart_index>
<checkout_onepage_index>
<reference name="footer">
<remove name="footer_newsletter"/>
</reference>
</checkout_onepage_index>
</layout>
local.xml runs at the last after calling all design xml file. So it will override any changes done in any xml.
Try to put the block which you want to hide in Comment in the checkout.xml.
You may also try something like this in local.xml:
<your_desired_handle><!-- replace handle here -->
<reference name="parent_block_of_footer_newsletter"> <!-- replace with the name of the parent block that contains your footer_newsletter block -->
<action method="unsetChild"><alias>alias_of_footer_newsletter_block</alias></action> <!-- replace the alias with the value of "as" attribute of your footer_newsletter block, or it's name if it does not have an "as" attribute -->
</reference>
</your_desired_handle>

How can I display a magento block in more than one location?

I'm trying to display the cross sell block in it's normal location as well as at the bottom of the page. There is more than one phtml template file involved so $this->getChildHtml does not work in the second location since the block is setup to only be on the cart.phtml file as of now.
In summary, how can I display the same block in more than one template file? I wan't to place these changes in my local.xml and do not want to modify core Magento template files.
The core layout directive for this block is set up as a child of the checkout.cart block:
<checkout_cart_index translate="label">
<!-- ... -->
<reference name="content">
<block type="checkout/cart" name="checkout.cart">
<!-- ... -->
<block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>
</block>
</reference>
</checkout_cart_index>
To add it to the footer, you might need to only establish another parent-child relationship in your local.xml:
<checkout_cart_index>
<reference name="footer">
<action method="insert"><!-- or "append" to add to the end -->
<child>checkout.cart.crosssell</child>
</action>
</reference>
</checkout_cart_index>
This approach relies on the stock page/html/footer.phtml template which contains an empty getChildHtml() call, which causes it to render all child blocks.
Note that the footer block class Mage_Page_Block_Html_Footer has a never-expiring block_html cache lifetime, and it does not evaluate child contents for its cache entry. You may need to disable the cache for this block or rewrite the block class to account for the varied content of the crosssell block.

Placement of Related products - Magento

I have a magento installation where I need to place related products in the center column. This is the easy part. I moved
<block type="catalog/product_list_related" name="catalog.product.related" after="container1" template="catalog/product/list/related.phtml"/>
From the right reference block, to the bottom of the center reference block.
With this I achieved to place the related products in the center column, but all the way at the bottom.
I need the related products to be placed just above the price block in the div (class: product-shop)
I tried to position it with the After/before parameter in the XML but this doesnt seem to work.
If I place the block code higher up in the XML it doesn't show at all.
Moving blocks is quite easy to do correctly (i.e. using best practices). Best practices include not customizing any core layout file when possible as well as working with original block instances rather than reinstantiating them. All of this can be achieve using the custom layout file available to end-implementers.
Create a local.xml file in your custom theme's layout folder e.g. app/design/frontend/[package]/[theme]/layout/local.xml, and in there add the following:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<!--
In Magento v1 a move is accomplished by unsetting in one place
and inserting in another. This is possible using just layout xml
when the "new" parent block is a "Mage_Core_Block_Text_List"
instance. Otherwise a template needs editing.
In Magento v2 there will be actual "move" functionality.
-->
<catalog_product_view>
<reference name="right">
<!-- remove the block name from a parent -->
<action method="unsetChild">
<block>catalog.product.related</block>
</action>
</reference>
<reference name="content">
<!-- add the block name to a parent -->
<action method="insert">
<block>catalog.product.related</block>
</action>
<!--
Mage_Core_Block_Abstract::insert() accepts multiple arguments,
but by default it will insert the added block at the beginning
of the list of child blocks.
-->
</reference>
</catalog_product_view>
</layout>
You can revert the change to the original layout xml file at this point.

Magento: How to add js or css file in custom 2column-left page using page.xml file

In Magento, how to add js or css file in custom two column left page using page.xml file.
I am using the following code in page.xml at line:168
<page_two_columns_left translate="label">
<label>All Two-Column Layout Pages (Left Column)</label>
**<reference name="head">
<action method="addJs"><script>sidebar_menu.js</script></action>
</reference>**
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template> </action>
<!-- Mark root page block that template is applied -->
<action method="setIsHandle"><applied>1</applied></action>
</reference>
</page_two_columns_left>
I can use the js/css by putting it in 2column-left.phtml but I don't thing it is convenient way. I want to add using xml.
Are the two asterisks up there actually on your code? If not, basically what you're doing there is correct. however:
<handle>
<reference name="head">
<action method="addJs"><script>prototype/prototype.js</script></action> <!-- adds a js referencing to the /js directory -->
<action method="addCss"><stylesheet>css/custom.css</stylesheet></action> <!-- adds CSS looking at the skin/ directories ( in reverse order: base/default, default/default, default/yourtheme, yourpackage/yourtheme -->
<action method="addItem"><type>skin_js</type><name>js/custom_script.js</name><params/></action> <!-- adds a js at the skin/ directories in the same manner as the above addCss directive -->
</reference>
<handle>
Please note that can be replaced by either default,modulename_controller_action e.g catalog_cart_index or in your case, page_two_columns_left
It is best to modify local.xml instead found inside app/design/frontend/yourpackage/yourtheme/layout/ if you have a custom skin to work with.
As much as possible, please don't touch page.xml inside the app/design/frontend/base/default/layout/ directory.

Magento - removing wishlist link in 1.4.2?

Previously in Magento, the wishlist link was added using the following (in wishlist.xml):
<action method="addWishlistLink"></action>
And you could override that and remove it using the following (in your local.xml):
<remove name="wishlist_link"/>
However, in the newest Magento, 1.4.2, they've changed how the wishlist link is added to the following:
<action method="addLinkBlock"><blockName>wishlist_link</blockName></action>
Anyone know how to remove the wishlist link now they’ve changed how it’s added?
It appears there's no publicly available way to reliably remove the wishlist link block from the layout. (you can skip to the end for a workaround)
The addLinkBlock assumes the presence of the block that's been passed, so using remove in the way you describe results in a fatal error being thrown
Fatal error: Call to a member function getPosition() on a non-object in /Users/alanstorm/Sites/magento1point4.2.dev/app/code/core/Mage/Page/Block/Template/Links.php on line 112
Here's the core code that causes that error
app/code/core/Mage/Page/Block/Template/Links.php
public function addLinkBlock($blockName)
{
$block = $this->getLayout()->getBlock($blockName);
$this->_links[$this->_getNewPosition((int)$block->getPosition())] = $block;
return $this;
}
This method assumes its going to be able to pull out a block by whatever name gets passed, so we can't just remove the wishlist_link block as we could in previous versions.
The only mechanism for removing a link appears to be the following method on the same block class
app/code/core/Mage/Page/Block/Template/Links.php
public function removeLinkByUrl($url)
{
foreach ($this->_links as $k => $v) {
if ($v->getUrl() == $url) {
unset($this->_links[$k]);
}
}
return $this;
}
However, this is done using string comparison, and there's no reliable way (that I know of) to generate a URL Object from a layout file, cast it as a string, and pass it into the method (this would be required, as there are numerous configuration settings that can change what the final string URL will be). That makes this method not helpful for our needs.
So, what we can do it modify the existing wishlist_link block to use a blank or non-existant template. This way the block still renders, but it renders as an empty string. The end result is we avoid the fatal error mentioned above, but still manage to remove the link from our selected pages.
The following would remove the link from all the pages using the default handle.
<!-- file: local.xml -->
<layout>
<default>
<reference name="wishlist_link">
<action method="setTemplate"><template>blank-link.phtml</template></action>
</reference>
</default>
</layout>
In your local.xml file,
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="root">
<reference name="top.links">
<!-- Remove wishlist link in magento 1.4.x and newer -->
<remove name="wishlist_link"/>
</reference>
</reference>
</default>
</layout>
You can remove the wishlist link from the admin panel System > Configuration > Wishlist > Enabled = "No"
Add the following to your local.xml file.
<reference name="top.links">
<remove name="wishlist_link"/>
</reference>
This works! I have removed Wishlink from Toplinks and wanted to add it back into another block but that doesn't seem possible when you remove it in this way. Sadly.
I know I'm years late here, but for all of those people who are still looking for answers to this.
I have a way to work around this issue that is only a bit of extra work but it's not hacky and it gives you FULL control of your top.links block.
Simply unset the top.links block and re-create it, it will be empty (no more wishlist_link block) and all you have to do is add whichever links you want inside of it! (Do all of this in your theme/layout/local.xml file of course).
<layout version="0.1.0">
<default>
<!-- HEADER -->
<reference name="header">
<!-- Unsetting the already existing top links block -->
<action method="unsetChild">
<name>topLinks</name>
</action>
<!-- Re-creating a new top links block -->
<block type="page/template_links" name="top.links" as="topLinks">
<!-- EXAMPLE: Account Dashboard Link -->
<action method="addLink" translate="label title" module="catalog">
<label>Account Dashboard</label>
<url helper="customer/getAccountUrl"/>
<title>Account Dashboard</title>
</action>
<!-- You can add any other links that you want -->
</block>
</reference>
</default>
</layout>
Also remember that for some links like Sign In and Log Out you will need to reference your top.links block inside the appropriate <customer_logged_out> and <customer_logged_in> handles instead of inside of <default> as a guide for this you can look at Magento's customer.xml file.
IMPORTANT: If there are any modules included in your project that add links to the top.links block, those links won't show up because local.xml is processed last, so just keep that in mind when using this method :)
I am a Certified Magento Front End Developer with over 3 years of experience and I have overcome LOTS of layout XML headaches to the point where we became best friends.

Resources