How to add new layout via local.xml? - magento

How can I add a new layout in magento using local.xml? I want it to appear in layouts list when I make new CMS page.

Layout in magento using local.xml
please go and follow this code.
http://www.codeboss.in/web-funda/2009/07/07/create-new-layout-in-magento/

Look at the very last block of code on this page. You can go into app/code/core/Mage/Page/etc/config.xml and add lines like this:
<TEMPLATE_LABEL module="page" translate="label">
<label>TEMPLATE NAME</label>
<template>page/TEMPLATE-FILENAME.phtml</template>
<layout_handle>page_HANDLE_NAME</layout_handle>
</TEMPLATE_LABEL>
replacing the capitalized words, e.g.
<home_format module="page" translate="label">
<label>Home Format</label>
<template>page/home-page.phtml</template>
<layout_handle>page_home_format</layout_handle>
</home_format>
Right before the end of the <page> ... </page> block of code.
Note: if you do it this way, you may not be able to upgrade Magento without losing your custom layout, as config.xml is a core file.

Related

Edit the catalog page for specific category

I am using Magento 1.8.1 and I am working on SEO. I need to put micro-data (schema code) for some category on that page only. I don't understand how to put the data for specific page because if I put any data in template page, it will update on all categories.
For example: I need to put data only for this page.
As I understand it, you want to add some code to only appear on a specific category view. You can add Javascript to the description field in the General Information tab of the category:
You can also add a template to before_body_end block of the page:
You can add additional layout directives here. This layout update:
<reference name="before_body_end">
<block type="core/template" name="seocode" template="seocode/seocode.phtml" />
</reference>
means render out your custom block (seocode) and template file (seocode.phtml) in the before_body_end block. The before_body_end block can be found in the page templates; i.e. page/1column.phtml or page/2columns-left.phtml.

Magento custom head code

How can I add a custom code i.e. Facebook retargetting or conversion pixel, etc. to a section of a SPECIFIC page? (not global)
I am using the latest magento version.
Thanks
You can accomplish this cleanly using Magento’s layout system. Create or modify the local.xml file in your current theme’s layout subdirectory. Add a new layout update like this:
<!-- Add Facebook retargeting pixel on success page. -->
<checkout_onepage_success>
<reference name="before_body_end">
<block type="core/template" name="fb_retargeting" template="tracking/fb_retargeting.phtml"/>
</reference>
</checkout_onepage_success>
Notice that this layout update is targeting the <checkout_onepage_success> handle, which corresponds to the /checkout/onepage/success page. If you need to target a different page, you have to figure out the layout handle for that page. The handle is created by combining the route name, controller name, and controller method into a single underscore-separated string.
Now you just need to create your template file in your current design’s template subdirectory. In my above example, the template being referenced should be created at: app/design/frontend/.../template/tracking/fb_retargeting.phtml. You would just put the markup for your tracking pixel in that file.
1) If its going to be a CMS pages you can add in the design tab Layout Update XML and add custom xml code, for example
<reference name="head">
<block type="module/block" name="module" template="module/view.phtml" ></block>
</reference>
2) If this need to be in other pages, you can add same code in local.xml of your theme file
go to app/design/frontend/base/your theme/template/page/html/head.phtml
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
$path = $url->getPath();
if($path == your specic page url){
your code.
}

Hide category menu using local.xml

How to hide category/menu bar on selected pages like login & registration using local.xml ?
I'm using magento 1.7.0.2
You need to remove block named 'catalog.topnav' for login and registration page handlers. The page handler similar to page URL, but all slashes replaced with '_'. For the login page it will be *customer_account_login* and for the registration page - *customer_account_create*. You can use
<remove name="[blockname]">
or
<action method="unsetChild"><block>[blockname]</block></action>
instructions, first allow you to remove block globally and the second one remove it from certain block.
The Layout update for default magento theme will looks like:
<?xml version="1.0"?>
<layout version="0.1.0">
<customer_account_login>
<remove name="catalog.topnav" />
</customer_account_login>
<customer_account_create>
<remove name="catalog.topnav" />
</customer_account_create>
</layout>
There is some explanation about Magento layouts which can be useful - http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-4-magento-layouts-blocks-and-templates
Remove nodes will be processed after all layout handles are merged, and are a good way to remove a block regardless of which layout handle loaded the block; you just want to get rid of it entirely for some handles! It also removes recursively, so all you need to specify is the layout handle.
On the other hand, you may only want to remove a block from a reference in a specific layout handle, in which case you should use unsetChild. It is often used to remove a block from a reference, but then re-insert the same block with a different position. This would not have been possible with remove.

How to add WYSIWYG Editor in Magento system configuration?

I want to add WYSIWYG editor in Magento system configuration.
And also get the value from the that is there option to do this.
Cheers.
I have found the answer from this post. Thanks to Marius for giving this answer.
First of all add this in any layout file, to load the editor in the config section:
<adminhtml_system_config_edit>
<update handle="editor"/>
<reference name="head">
<action method="setCanLoadTinyMce"><load>1</load></action>
</reference>
</adminhtml_system_config_edit>
Now create your own field renderer. It has to be a block inside your module:
<?php
class Namespace_Module_Block_Adminhtml_System_Config_Editor extends Mage_Adminhtml_Block_System_Config_Form_Field implements Varien_Data_Form_Element_Renderer_Interface{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
$element->setWysiwyg(true);
$element->setConfig(Mage::getSingleton('cms/wysiwyg_config')->getConfig());
return parent::_getElementHtml($element);
}
}
Now for the element inside the system.xml set the frontend_type 'editor' and the frontend_model your new block
<fieldname translate="label">
<label>Field label </label>
<frontend_type>editor</frontend_type>
<frontend_model>module/adminhtml_system_config_editor</frontend_model>
<sort_order>150</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</fieldname>
There are some issues when changing the config scope to a website or a store view. The textarea does not become 'disabled'. But if you can ignore this, you can use it without any problems.
What you need to do, is add a WYSIWYG editor with its appropriate adminhtml controller. After this, you can load the editor for every configfield you specify.
Try reading this article. It is a step-by-step guide how to add the editor.

How to remove 'add to cart' button from one cms page only?

I have created a web store with custom CMS page which has custom layout too. This page will show all the products of the store.
On that CMS page all the product is displaying but
I want to remove 'add to cart' button, 'add to wishlist' link and 'add to compare' link from products
I want to remove these links from that specific CMS page only.
I tried
<remove name="" />
in Layout Update XML of that CMS page but I can't get specific names to remove and while searching I tried every possible name but no success.
Any suggestions?
If you have used a custom layout and you are displaying all products on that page then you must have used block type to display all products in content of that page.
Something like
{{block type="catalog/product_list_random" name="product" template="catalog/product/list.phtml"}}
Simply make a new file and save it on same loction where list.phtml is saved (obviously with different name say new.phtml
Put that new.phtml instead of list.phtml
And delete whatever you don't want to display on that page from new.phtml
You only can remove whole blocks with layout updates like that, but those links and buttons are not separate blocks but get rendered within the Mage_Catalog_Block_Product_List block. You will have to replace the template of this block with your own:
copy /app/design/frontend/base/default/template/catalog/product/list.phtml to /app/design/frontend/YOUR/THEME/template/WHATEVER/catalog/product/list.phtml (use your theme directory and a directory name under template that refers to your CMS page)
edit this copy and remove the links and buttons
in the layout update handle for your CMS page, add:
XML:
<reference name="product_list">
<action method="setTemplate" template="WHATEVER/catalog/product/list.phtml" />
</reference>
(assuming that the product list block is called product_list)
Then, depending on what you want to remove, you can put between the "default" tags the following lines:
<remove name="cart_sidebar" /> "
<remove name="catalog.compare.sidebar" /> "
http://www.hostknox.com/tutorials/magento/remove-default-blocks/manual-removal

Resources