Remove layout handle from xml - magento

I have a layout defined in some xml file found in a community module. Somehow I want to add a condition (ifconfig) by which the content of the block to be rendered or completely remove that handle and create one by myself so that I can have access to the block.
To be more specific, this is the handle I have in udprod.xml
<_udprod_catalog_product_edit>
<reference name="content">
<block type="core/template" template="udprod/product_edit.phtml" />
</reference>
</_udprod_catalog_product_edit>
<adminhtml_catalog_product_edit>
<update handle="_udprod_catalog_product_edit" />
</adminhtml_catalog_product_edit>
As you can see, the block has no name I can rely on. Is there any way I can remove the <_udprod_catalog_product_edit> handle from an xml file?
Thank you

I am not sure that is possible, but I have a work around which I use to fix buggy 3rd party extensions:
Create a new module
A very simple one, only 2 files are required.
app/etc/modules/Namespace_Fixer.xml:
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Fixer>
<active>true</active>
<codePool>local</codePool>
<depends>
<Broken_Module/>
</depends>
</Namespace_Fixer>
</modules>
</config>
Note the depends, this is very important so that it is loaded after.
app/code/local/Namespace/Fixer/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Fixer>
<version>0.1.0</version>
</Namespace_Fixer>
</modules>
<global>
</global>
<frontend>
<layout>
<updates>
<broken_module> <!-- update this -->
<file>namespace/module_fixed.xml</file>
</broken_module>
</updates>
</layout>
</frontend>
</config>
Override the layout file to point to our new one.
Duplicate the layout XML
You want to point at the new XML, in there you can do the right thing and add a name to the block and call it where ever you want.

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?

How to make a Magento extension to replace prototype.js w/ an alternate version in adminhtml only

I need to call an alternate js/prototype1_6_0_3.js file into my admin only, and keep the original js/prototype.js for the user/customer front-end. I had to qickly upgrade the original js/prototype.js file to 1.7.0.1 b/c of an issue that popped up when IE10 did one of its auto-updates.
Currently my extension causes the admin to be mostly blank and very broken.
can someone point out what I'm doing wrong.
thanks.enter code here
Here is what I'm trying to do:
app\design\adminhtml\default\default\layout\adminprototypeversion.xml
<?xml version="1.0"?>
<layout>
<adminhtml>
<reference name="head">
<action method="removeItem"><type>js</type><name>prototype/prototype.js</name></action>
<action method="addJs"><script>prototype/prototype1_6_0_3.js</script></action>
</reference>
</adminhtml>
</layout>
app\code\local\Alphacard\Adminprototypeversion\etc\config.xml
<config>
<modules>
<Alphacard_Adminprototypeversion>
<version>0.1.0</version>
</Alphacard_Adminprototypeversion>
</modules>
<adminhtml>
<layout>
<updates>
<Adminprototypeversion>
<file>adminprototypeversion.xml</file>
</Adminprototypeversion>
</updates>
</layout>
</adminhtml>
</config>
app\etc\modules\Alphacard_Adminprototypeversion.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Alphacard_Adminprototypeversion>
<active>true</active>`enter code here`
<codePool>local</codePool>
</Alphacard_Adminprototypeversion>
</modules>
</config>
In your app\design\adminhtml\default\default\layout\adminprototypeversion.xml
You should be able to just rename the <adminhtml> node to <default>
Magento already knows it's for "adminhtml" because of the config.xml layout update in your module being declared within the "adminhtml" area.

My custom CMS Layout Template in Magento is not loaded

I have created custom CMS layout for Magento according this tutorial. On my localhost(XAMPP on Win7) it is working, but when I have uploaded all 3 files to my web:
app/code/local/Lorinc/cmsLayout/etc/config.xml
app/design/frontend/sportsfans01/default/template/page/cmsLayout.phtml
app/etc/modules/Lorinc_cmsLayout.xml
And it is not working there.
Here is the code of config.xml
<?xml version="1.0"?>
<config>
<modules>
<Lorinc_cmsLayout>
<version>0.1.0</version>
</Lorinc_cmsLayout>
</modules>
<global>
<page>
<layouts>
<cmsLayout translate="label">
<label>cmsLayout</label>
<template>page/cmsLayout.phtml</template>
<layout_handle>cmsLayout</layout_handle>
</cmsLayout>
<!-- add more layouts here -->
</layouts>
</page>
</global>
</config>
And here is Lorinc_cmsLayout.xml
<?xml version="1.0"?>
<config>
<modules>
<Lorinc_cmsLayout>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page />
</depends>
</Lorinc_cmsLayout>
</modules>
</config>
I have tried everything. I have changed files and folder permissions (files 0644, folders 0755), i have used magento-cleanup.php, my cache is disabled, I have tried to logout and login again and nothing works. Any ideas what is wrong there?
just looked at your question and the first thing I saw is that you have a wrong folder structure:
The path app/design/frontend/sportsfans01/default/template/page/cmsLayout.phtml
has to be changed to
app/design/frontend/default/sportsfans01/template/page/cmsLayout.phtml
Don't know if its just a typo of yours!
Furthermore you could check the logs of magento:
var/log/exception.log
var/log/system.log
Hope this will help
Regards
Vince
Please try this. I found it in App/code/core/Mage/Page/etc/config.xml for the 1column.phtml layout
<global>
<page>
<layouts>
<cmsLayout module="page" translate="label">
<label>cmsLayout</label>
<template>page/cmsLayout.phtml</template>
<layout_handle>page_cmsLayout</layout_handle>
</cmsLayout>
<!-- add more layouts here -->
</layouts>
</page>
</global>
If this won't help please try with changing different theme folder.Be sure to avoid typo mistake.
Problem finally solved. I already had one custom layout (called HomeLayout) on that page so I just merged that 2 layouts. Here is the code of app/code/local/Lorinc/HomeLayout/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Lorinc_HomeLayout>
<version>0.1.0</version>
</Lorinc_HomeLayout>
</modules>
<global>
<page>
<layouts>
<Lorinc_HomeLayout translate="label">
<label>HomeLayout</label>
<template>page/HomeLayout.phtml</template>
<layout_handle>HomeLayout</layout_handle>
</Lorinc_HomeLayout>
<Lorinc_cmsLayout translate="label">
<label>cmsLayout</label>
<template>page/cmsLayout.phtml</template>
<layout_handle>cmsLayout</layout_handle>
</Lorinc_cmsLayout>
<!-- add more layouts here -->
</layouts>
</page>
</global>
</config>
And it works perfect.

Magento layout.xml update with url helper - I always get an array instead of an url

I want to insert a canonical meta tag in some sites which will be generated by an extension. So I inserted following code in the layout.xml of the extension:
<reference name="head">
<action method="addLinkRel">
<rel>canonical</rel>
<href><url helper="core/url/getCurrentUrl"/></href>
</action>
</reference>
But I always just get "Array" instead of the url. What am I doing wrong?
If I will get it work, do I get just the www.mystore.com/productxy.html or the complete url with www.mystore.com/productxy.html?page=3.
Because I only need the first one, without the parameters.
Your code was almost right. Though you can only use the helper attribute in layout xml on the tags directly under the <action> tag. Luckily, you mistakenly added the extra <url> tag, so this should work:
<reference name="head">
<action method="addLinkRel">
<rel>canonical</rel>
<href helper="core/url/getCurrentUrl"/>
</action>
</reference>
Mage_Core_Helper_Url::getCurrentUrl() returns the REQUEST_URI from your $_SERVER variable. That variable includes the query, so unfortunately it's not as usable as you probably thought it would be.
I'm pretty sure you can't do that. You're getting an Array because it's interpreting the <url helper="core/url/getCurrentUrl"/> XML node into an Array. This action processes the function addLinkRel instead and not the <url /> helper at all (never).
The better (and much more fun) way of doing this is by creating a module where you can define a new block type that renders <link rel='canonical' href='{$currentUrl}' />.
Here's how I would do it, and it would take about 4 files:
app/code/community/Electricjesus/Canonical/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Canonical>
<version>0.1.0</version>
</Electricjesus_Canonical>
</modules>
<global>
<blocks>
<canonical>
<class>Electricjesus_Canonical_Block</class>
</canonical>
</blocks>
</global>
</config>
app/code/community/Electricjesus/Canonical/Block/Link.php
<?php
class Electricjesus_Canonical_Block_Link extends Mage_Core_Block_Template {
}
app/design/frontend/base/default/template/canonical/link.phtml
<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); ?>
<link rel="canonical" href="<?php echo $currentUrl ?>" />
app/etc/modules/Electricjesus_Canonical.xml
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Canonical>
<active>true</active>
<codePool>community</codePool>
<version>0.1.0</version>
</Electricjesus_Canonical>
</modules>
</config>
So, the way to do it now here is (in your local.xml):
<reference name="head">
<block type="canonical/link" name="canonical_link" template="canonical/link.phtml" />
</reference>
So this is basically just a rough draft I cooked up in a few minutes, I've used the same solution for another kind of problem (but similar scope). So, give it a spin if you want.

Overriding Core Blocks

I'm try to overriding Mage_Core_Block_Messages
I'm create module
Mycompany_Core.xml and save in path app/etc/modules/Mycompany_Core.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Core>
<active>true</active>
<codepool>local</codepool>
</Mycompany_Core>
</modules>
</config>
next I was create in app/code/local/Mycompany/Core/Block/Messages.php
class Mycompany_Core_Block_Messages extends Mage_Core_Block_Messages
{
//update method
}
and add config.xml in app/code/local/Mycompany/Core/etc/config.xml
<config>
<modules>
<Mycompany_Core>
<version>0.0.1</version>
</Mycompany_Core>
</modules>
<global>
<blocks>
<core>
<rewrite>
<messages>Softdk_Core_Block_Messages</messages>
</rewrite>
</core>
</blocks>
</global>
</config>
But i don't see any result on frontend, I'm wonder where I'm make mistake.
Thx for help.
There are two things that caught my eye.
1.) In your module's registration file, it should be codePool and not codepool (as also said by David in comments)
2.) What is Softdk? If that is the name of your new module, then replace Mycompany with Softdk everywhere in your module.
Clear cache and voila!

Resources