Two layouts configuration in config.xml - magento

I am trying to use two layout files, one for taking data from user and saving it into database and other to display content from it.I don't know how to configure config.xml for adding two layout files in magento.
Here is my layout configurations in config.xml
<layout>
<updates>
<helloworld>
<file>displaydata.xml</file>
</helloworld>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>

You can use your single layout file to define multiple handlers.
http://code.tutsplus.com/tutorials/custom-layouts-and-templates-with-magento--cms-21419
In this tutorial, at last it is specified how to use our custom layout for extension.
You can add new handler like follows.
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_index_index>
<reference name="content">
<block type="mymodule/mymodule" name="mymodule" template="mymodule/mymodule.phtml" />
</reference>
</mymodule_index_index>
<!-- this is new handler -->
<mymodule_index_test>
<reference name="content">
<block type="mymodule/mymodule" name="mymodule" template="mymodule/test.phtml" />
</reference>
</mymodule_index_test>
</layout>
And in controller you can add relevant action for this new handler

Related

Magento > remove custom action method from layout

I'm using a module that contains the action method 'SearchAutocomplete'. Could i remove this method somehow, just like with removeItem?
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<block type="searchautocomplete/layout" name="search.block">
<action method="SearchAutocomplete" ifconfig="searchautocomplete/general/enabled" />
</block>
</default>
</layout>
Right now the only solution i have is to make the changes in the xml file, which is not update-safe. Is there a better way?
According this XML you can disable this method in module configuration. Just find configuration and in General section should be selector for disable this.

Magento 1.9 - modifying layout

What is the best way of modifying a layout for Magento 1.9? I've been updating layouts using the admin backend but now need to do this programatically. Several articles have mentioned using layout.xml but for some reason, my system isn't picking up the layout updates.
Specifically, this is what I'm trying to modify:
Original layout
<block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
<action method="addOptionRenderer">
<type>text</type>
<block>catalog/product_view_options_type_text</block>
<template>catalog/product/view/options/type/text.phtml</template>
</action>
...
</block>
Modified layout
<block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
<action method="addOptionRenderer">
<type>text</type>
<block>catalog/product_view_options_type_text</block>
<template>catalog/product/view/options/type/newfile.phtml</template>
</action>
...
</block>
My modified layout is located in:app/design/frontend/default/(company name)/(module name)/layout/layout.xml
layout.xml (just checking to see if it will add the block, "test"):
<layout>
<default>
<block type="core/text_list" name="test"/>
</default>
</layout>
app/code/local/(company name)/(module name)/etc/config.xml:
<config>
<modules>
...
</modules>
<frontend>
<layout>
<updates>
<(module name)>
<file>local.xml</file>
</(module name)>
</updates>
</layout>
</frontend>
</config>
Can somebody point me in the right direction? Thanks!
Here are two things I notice which should be changed:
Your layout update file should have a unique name that won’t conflict with existing modules. In your config.xml you have specified <file>local.xml</file>. The problem with this is, local.xml will already be loaded automatically by Magento. So you should not use that filename for your layout update file if you are trying to add a new one specific to your module, however you may add miscellaneous updates to that file and they will get picked up automatically and applied last to the final merged layout.
Behind the scenes there’s an <updates /> section of the global config that contain nodes with all the file names to load. Once the files listed in the config have been combined, Magento will merge in one last xml file, local.xml.
Your layout update file app/design/frontend/default/(company name)/(module name)/layout/layout.xml does not appear to be in the right location. You should create your new layout update file at: app/design/frontend/base/default/layout/(company name)/(module_name).xml. Then, you need to update your config.xml to point to this file: <file>(company name)/(module name).xml</file>.
Because of the ability to use different themes in Magento and its fallback mechanism, all extension related theme files are placed in “base/default” package for frontend...

How to load a js file on magento admin dashboard

I am trying to load a js file through XML on the dashboard page of magento admin, but am unable to get it right.
Here is the part of code that I have added in my config file:
<config>
<adminhtml>
<layout>
<updates>
<anattadesign_abandonedcarts>
<file>my_extension.xml</file>
</anattadesign_abandonedcarts>
</updates>
</layout>
</adminhtml>
</config>
And my contents of my_extension.xml which is placed under /app/design/adminhtml/default/default/layout/ is:
<layout>
<default>
<reference name="head">
<action method="addJs"><script>my_extension/adminhack.js</script></action>
<action method="addJs"><script>prototype/prototype.js</script></action>
</reference>
</default>
</layout>
I understand that I am trying to load a js file for the whole admin this way, but I would like to know both, loading on a certain page, and how to find out the name if I want to load it on a certain page and if default is the correct one to make it load on all admin pages.
Using default should load it on all pages, indeed.
To load it on just admin dashboard use the (full 3 element) route with underscores as separators to the page. For the dashboard this is Adminhtml/(controllers)/Dashboard(Controller)/index(Action).
<layout>
<adminhtml_dashboard_index>
<reference name="head">
<action method="addJs"><script>my_extension/adminhack.js</script></action>
<action method="addJs"><script>prototype/prototype.js</script></action>
</reference>
</adminhtml_dashboard_index>
</layout>
N.B. I have not tested this code, but I think it should do it.

How to override the admin template file in magento?

I need to override the "adminhtml/sales/order/create/items/grid.phtml" file to display some custom text under each item while creating new order from admin. I want this to be done through custom module. Anyone can suggest how to override the admin template files? Any help is really appreciated
I Recommend you that create a new template and add new design in your module with the layout update for the adminhtml section.
For example:
In your config.xml of your custom extension you can update the layout of adminhtml with:
<adminhtml>
<layout>
<updates>
<adminhtml>
<file>yourcustomlayout.xml</file>
</adminhtml>
</updates>
</layout>
</adminhtml>
Ok, then since this layout you can write the next code to add a css for example:
<layout>
<default>
<reference name="head">
<action method="addCss">
<name>aw_all/css/window.css</name>
</action>
</reference>
</default>
</layout>
In your case you need add you custom template for your block
<layout>
<handle>
<reference name="content">
<block type="smspremium/adminhtml_smspremium" name="smspremium">
<action method="setTemplate">
<template>customtemplate.phtml</template>
</action>
</block>
</reference>
</handle>
</layout>
If you want to discart all the block and replace with your block you can made unsetChild
<layout>
<handle>
<reference name="content">
<action method="unsetChild"><name>your.last.block</name></action>
<block type="smspremium/adminhtml_smspremium" name="smspremium">
<action method="setTemplate">
<template>customtemplate.phtml</template>
</action>
</block>
</reference>
</handle>
</layout>
This work same the frontend layout, only with the diference of the directory since you store your files.
For Templates:
app/design/adminhtml/default/default/templates
For layout:
app/design/adminhtml/default/default/layout
Hope help you
Basically, you have to declare a new layout file for your module for adminhtml area, than set a new template path using setTemplate method and reference[name] node.
First of all I'm not believe this is the correct way of overriding adminhtml templates. But I try this approach and it works, So just wanna share.
Add this to your custom Module config.xml
<stores>
<admin>
<design>
<theme>
<default>default</default>
<template>mycustom</template>
</theme>
</design>
</admin>
</stores>
Now You can just override by copying templates from default to mycustom
app\design\adminhtml\default\default\template\sales\order\view\history.phtml app\design\adminhtml\default\mycustom\template\sales\order\view\history.phtml
You can find the detailed instructions for overriding Magento admin files here http://www.techawaken.com/creating-a-new-magento-admin-theme/

Magento: Add a custom view.phtml to my custom product type

So I created a custom view.phtml file to display a different layout on the product page for event registration. I am able to display that custom view file if i add it to the XML field under the design tab.
What i want to do is create a custom product type in magento that already uses my new view-events.phtml. I know how to create the custom product type but how do I get the new product type to use my custom view file?
In your module's config.xml:
<config>
<global>
<catalog>
<product>
<type>
<!-- Change "custom" to your custom product type -->
<custom>
<!-- See app/code/core/Mage/Catalog/etc/config.xml for hints here -->
</custom>
</type>
</product>
</catalog>
</global>
<frontend>
<layout>
<updates>
<!-- Use your module's name here -->
<your_module>
<file>your_module.xml</file>
</your_module>
</updates>
</layout>
</frontend>
Then in the your_module.xml layout file just referenced:
<layout>
<PRODUCT_TYPE_custom>
<reference name="product.info">
<action method="setTemplate">
<template>path/to/your/view-events.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_custom>
</layout>

Resources