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?
Related
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.
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.
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.
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.
I'm very new to Magento and I'm trying to add a new tab to the customer view of Magento backend.
I have made a new extension/module for it. Here are some extracts of my etc/config.xml:
<global>
<blocks>
<showidea>
<class>Whatever_Extendcustomer_Block</class>
</showidea>
</blocks>
<!-- ... -->
</global>
<adminhtml>
<layout>
<updates>
<showidea>
<file>whatever_extendcustomer.xml</file>
</showidea>
</updates>
</layout>
</adminhtml>
And here the contents of the whatever_extendcustomer.xml file:
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTab">
<name>extendcustomer_showidea</name>
<block>extendcustomer/adminhtml_customer_showidea</block>
</action>
</reference>
</adminhtml_customer_edit>
Of course this block is existing and it extends the Mage_Adminhtml_Block_Template and implements Mage_Adminhtml_Block_Widget_Tab_Interface.
When I go to details of a customer I get now the error: Wrong tab configuration.
In Magento's error log stands:
exception 'Mage_Core_Exception' with message 'Invalid Blocktype:
Mage_Extendcustomer_Block_Adminhtml_Customer_Showidea' in
/var/www/vhosts/whatever/htdocs/app/Mage.php:594
And I think this is the problem, because Mage_Extendcustomer is wrong. It should be Whatever_ ... but I don't know why it is prepending the Mage_ instead of my Whatever_ namespace.
I hope someone can give me the clue!
Thanks.
You should use showidea instead of extendcustomer in your layout file :
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTab">
<name>extendcustomer_showidea</name>
<block>showidea/adminhtml_customer_showidea</block>
</action>
</reference>
</adminhtml_customer_edit>
Because it's what you've defined in the blocks config :
<blocks>
<showidea>
<class>Whatever_Extendcustomer_Block</class>
</showidea>
</blocks>