Add new layout to magento for output category - magento

I have custom layout for category.
<CATEGORY_8>
<reference name="root">
<action method="setTemplate"><template>page/category_8.phtml</template></action>
</reference>
<reference name="left">
<block type="catalog/category_view" name="catalog.leftnav.within" before="-" template="catalog/layer/within.phtml "/>
</reference>
<reference name="category.products">
<action method="setTemplate"><template>catalog/category/8/view.phtml</template></action>
</reference>
<reference name="catalog.leftnav">
<action method="setTemplate"><template>catalog/layer/view_8.phtml</template></action>
</reference>
<reference name="product_list">
<action method="setTemplate"><template>catalog/product/list_8.phtml</template></action>
</reference>
</CATEGORY_8>
I want create new layout and I want apply this layout for category.
I created new layout
<page_new_new module="page" translate="label">
<label>Layout new</label>
<template>page/category_8.phtml</template>
<layout_handle>page_new_new</layout_handle>
</page_new_new>
How I can setup templates for this layout?
I don't want using "Custom Layout Update" field inside admin.
I want use only "Page Layout" field?

I would insert the layout xml block (your first code part with CATEGORY_8) into design/frontend/*/*/layout/page.xml (your actual frontend design folder, most possibly default/default) and create an extension with a simple config.xml, something like this:
<?xml version="1.0"?>
<config>
<global>
<page>
<layouts>
<page_new_new module="page" translate="label">
<label>Layout new</label>
<template>page/category_8.phtml</template>
<layout_handle>page_new_new</layout_handle>
</page_new_new>
</layouts>
</page>
</global>
</config>
To create an extension just create the folder structure in your app/code/local directory:
YourCompanyName/ModuleNameYouLike/etc
and put this [config.xml] in, you will also need an xml file in app/etc/modules directory:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<YourCompanyName_ModuleNameYouLike>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page />
</depends>
</YourCompanyName_ModuleNameYouLike>
</modules>
</config>
After refreshing configuration and layout cache you will see Layout new for pages from the Page layout dropdown.

Related

Magento - Trouble loading module layout xml file

I'm creating a simple sample module in magento 1.9 and I am hoping to do display a custom block on the front end product page - through my module; however I have stumbled in trouble early on.
In my modules config.xml I have defined a front end layout update, below as the full config.xml file
<?xml version="1.0"?>
<config>
<modules>
<MP_SampleModule>
<version>0.0.1</version>
</MP_SampleModule>
</modules>
<frontend>
<layout>
<updates>
<MP_SampleModule>
<file>samplemodule.xml</file>
</MP_SampleModule>
</updates>
</layout>
</frontend>
</config>
I have confirmed the module is loading.
For the layout file, I created samplemodule.xml :
\app\design\frontend\rwd\default\layout\samplemodule.xml
rwd is my active theme.
the samplemodule.xml contents are as follows:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<action method="setTitle">
<rel>DID THIS WORK??</rel>
</action>
</reference>
</default>
</layout>
However it seems Magento is not picking up this file at all. I have tried placing invalid xml in the samplemodule.xml in the hope Magento would throw an error confirming it is at least being loaded, but as no error is thrown I'm lead to believe it is simply being ignored.
I've read countless other similar questions on SO and on other sites but i've hit a brick wall so any insight into the issue would be welcomed and anything leading to a solution would be applauded.
Thanks
After a few days of not making any progress with this, I decided to try again. In the end I changed the contents of my files to the following which seems to have done the trick:
\app\code\community\MP\SampleModule\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<MP_SampleModule>
<version>0.0.1</version>
</MP_SampleModule>
</modules>
<frontend>
<layout>
<updates>
<MP_SampleModule module="MP_SampleModule">
<file>mp_samplemodule.xml</file>
</MP_SampleModule>
</updates>
</layout>
</frontend>
</config>
\app\design\frontend\base\default\layout\mp_samplemodule.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="before_body_end">
<block type="core/template"
name="test"
template="mp/samplemodule/test.phtml"/>
</reference>
</default>
</layout>
This now correctly outputs contents of test.phtml (\app\design\frontend\base\default\template\mp\samplemodule\test.phtml) near the end of the page.
Thanks for all the insights provided which was helpful in finding the solution.
First make sure you are putting it in your theme folder. Second the updates reference the Module Name not its namespace so it would be
<frontend>
<layout>
<updates>
<Sample_Module>
<file>samplemodule.xml</file>
</Sample_Module>
</updates>
</layout>
</frontend>
Then try adding this: <layout version="0.1.0"> instead of layout. Then add this:
<default>
<reference name="head">
<action method="setTitle"><rel>DID THIS WORK??</re></action>
</reference>
</default>
this will set the title of every page.
Other things to check: is the module being loaded?

Override AddItemRenderer default in Admin Magento Extension

I've created a magento (1.7 CE) local module to add, in the Admin section, some info to the product list displayed in the Orders received.
Internally all seems to work good except that i'm not succeeding in replacing the template used to render each product line in the order.
In app/design/adminhtml/default/default/layout/sales.xml i have this code
<adminhtml_sales_order_view>
<reference name="head">
<action method="addJs"><file>mage/adminhtml/giftmessage.js</file></action>
<action method="addJs"><file>mage/adminhtml/giftoptions/tooltip.js</file></action>
</reference>
<reference name="content">
<block type="adminhtml/sales_order_view" name="sales_order_edit"></block>
</reference>
<reference name="left">
<block type="adminhtml/sales_order_view_tabs" name="sales_order_tabs">
<block type="adminhtml/sales_order_view_tab_info" name="order_tab_info" template="sales/order/view/tab/info.phtml">
<block type="adminhtml/sales_order_view_messages" name="order_messages"></block>
<block type="adminhtml/sales_order_view_info" name="order_info" template="sales/order/view/info.phtml"></block>
<block type="adminhtml/sales_order_view_items" name="order_items" template="sales/order/view/items.phtml">
<action method="addItemRender"><type>default</type><block>adminhtml/sales_order_view_items_renderer_default</block><template>sales/order/view/items/renderer/default.phtml</template></action>
<...
I would like to replace the template set by the LAST line you see (the addItemRenderer).
In my module config.xml i have
<adminhtml>
<layout>
<updates>
<my_ext>
<file>myext_update.xml</file>
</my_ext>
</updates>
</layout>
</adminhtml>
and in app/design/adminhtml/default/default/layout/myext_update.xml i have
<?xml version="1.0"?>
<admin_sales_order_view>
<reference name="left">
<reference name="sales_order_tabs">
<reference name="order_tab_info">
<reference name="order_items">
<action method="addItemRender">
<type>default</type>
<block>adminhtml/sales_order_view_items_renderer_default</block>
<template>myext/sales/order/view/items/renderer/default.phtml</template>
</action>
</reference>
</reference>
</reference>
</reference>
</admin_sales_order_view>
Obviously i have the file in app/design/adminhtml/default/default/template/myext/sales/order/view/items/renderer/default.phtml
but it is still not used.
Do you have a solution?
Found the solution after some day of struggling...
the code and the method is all good, but i mistyped the handle name to update in the myext_update.xml
i wrote
<admin_sales_order_view>
but , as in the original sales.xml, the handle name was
<adminhtml_sales_order_view>
Actually this wont work as the way you proceeded. You need to update the layouts.
Have some idea about layout updates also render the layout in yout module
Check here http://www.magentocommerce.com/design_guide/articles/intro-to-layouts

Cannot override block template in magento

I have read quite many posts, but for me nothing is working. Task is quite simpe - I need to override core template review/product/view/list.phtml with my own, let's say my_list.phtml
My configuration is as follows. Layout.xml (head modification is working)
<layout version="0.1.0">
<review_product_list>
<reference name="head">
..
</reference>
<reference name="product.info">
<block type="review/product_view_list" name="myreview.product_additional_data"
as="myreview_product_additional_data" template="review/product/view/my_list.phtml"/>
</reference>
</review_product_list>
Config.xml
<frontend>
<layout>
<updates>
<myreview>
<file>myreview/layout.xml</file>
</myreview>
</updates>
</layout>
</frontend>
I can change core file review.xml and it works as expected, this line
<block type="review/product_view_list" name="product.info.product_additional_data" as="product_additional_data" template="review/product/view/list.phtml">
but this is not I am expecting.
If I change
reference name="product.info"
to
reference name="content" My template shows up, but not in place. If I try to debug, blocks are rendered.
<review_product_list>
<reference name="product.info.product_additional_data">
<action method="setTemplate">
<tpl>review/product/view/my_list.phtml</tpl>
</action>
</reference>
</review_product_list>
or
<review_product_list>
<action method="setTemplate" block="product.info.product_additional_data">
<tpl>review/product/view/my_list.phtml</tpl>
</action>
</review_product_list>

magento - 'invalid block type' exception

i created a new block in my own module of Customer, here's the config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Nauba_Customer>
<version>1.6.2.0.3</version>
</Nauba_Customer>
</modules>
<global>
<resources>
<nauba_customer_setup>
<setup>
<module>Nauba_Customer</module>
</setup>
</nauba_customer_setup>
</resources>
<blocks>
<nauba_customer>
<class>Nauba_Customer_Block</class>
</nauba_customer>
<customer>
<rewrite>
<form_register>Nauba_Customer_Block_Form_Register</form_register>
</rewrite>
</customer>
</blocks>
<models>
<customer>
<rewrite>
<customer>Nauba_Customer_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>
<frontend>
<routers>
<customer>
<args>
<modules>
<Nauba_Customer before="Mage_Customer">Nauba_Customer</Nauba_Customer>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
now i'm trying to call it in the home page, so i've specified it in the page.xml layout:
<!-- this is only the home page section -->
<page_homepage translate="label">
<label>Homepage</label>
<reference name="root">
<!--reference name="head">
<action method="removeItem"><type>skin_css</type><name>css/styles.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/styles-ie.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/widgets.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/print.css</name></action>
</reference-->
<block type="page/html" name="category_links" template="page/html/category_links.phtml" />
<block type="cms/block" name="homepage_slider_image_1" as="homepage_slider_image_1">
<action method="setBlockId"><block_id>homepage_slider_image_1</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_2" as="homepage_slider_image_2">
<action method="setBlockId"><block_id>homepage_slider_image_2</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_3" as="homepage_slider_image_3">
<action method="setBlockId"><block_id>homepage_slider_image_3</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_4" as="homepage_slider_image_4">
<action method="setBlockId"><block_id>homepage_slider_image_4</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_1" as="homepage_event_banner_1">
<action method="setBlockId"><block_id>homepage_event_banner_1</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_2" as="homepage_event_banner_2">
<action method="setBlockId"><block_id>homepage_event_banner_2</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_3" as="homepage_event_banner_3">
<action method="setBlockId"><block_id>homepage_event_banner_3</block_id></action>
</block>
<block type="nauba_customer/list_ordercrosssell" name="ordercrosssell" as="ordercrosssell" template="nauba_customer/list/ordercrosssell.phtml">
</block>
<action method="setTemplate"><template>page/home.phtml</template></action>
<!-- Mark root page block that template is applied -->
<action method="setIsHandle"><applied>1</applied></action>
<action method="setLayoutCode"><name>page_homepage</name></action>
</reference>
</page_homepage>
but it doesn't work when i call it in the home template with:
($this->getChildHtml('ordercrosssell'))
Also i've tried to create it by:
$this->getLayout()->createBlock('ordercrosssell')
but it raise this exception 'invalid block type'. any help?
The createBlock() method would take in the whole block alias name (nauba_customer/list_ordercrosssell), not just ordercrosssell. The reason that getChildHtml() can take in just ordercrosssell is because the child block's name is defined in the layout xml.
Not totally sure what may be wrong with your layout.xml, but you should probably drop the underscore in your aliases. So instead of nauba_customer just go with naubacustomer or ideally something slightly shorter than that for ease of use.
I'm not 100% sure whether it's a problem or not but in general it's better to follow existing convention as #Herve mentioned with underscores vs. slashes in class aliases, b/c things can get a little hairy.
In some cases (Magento 1.9), if we forgot to use construct function in block PHP file then put it and the issue will be fixed:
protected function _construct()
{
parent::_construct();
}
In some other cases (Magento 1.9), if we have wrong file permissions/ownership, we get the same exception. Fixing permission/ownership solved it. Hope it saves someone else a couple of hours ...

Magento: Add custom module block in checkout/cart

I have created a custom module that shows a block in "/checkout/cart/".
I use this code in default layout "checkout.xml" file:
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="mymodule/myblock.phtml"/>
How can I edit my module config file to load the phtml block in "/checkout/cart/" without editing the default layout files.
Thanks for help.
Create a local.xml file in your custom theme folder.
In the local.xml file reference the encapsulating block and add your block as a new node.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference
name="checkout.cart">
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="mymodule/myblock.phtml"/>
</reference>
</default>
</layout>

Resources