I have created three different modules for magento custom column layout, magento custom prices and magento custom file extension(this extension supposed to allow any video file) inside the code/local codepool folder.
I followed the folder structure of each module from the code/core codepool. However these modules are not recognized.
To test if my code is correct, I paste the magento custom column layout config.xml code to app/code/core/Mage/Page/etc to update it and it works.
Question:
How can my code works in code/local codepool?
This is a portion of my working magento custom column layout config.xml file.
<layouts>
<empty module="page" translate="label">
<label>Empty</label>
<template>page/empty.phtml</template>
<layout_handle>page_empty</layout_handle>
</empty>
<one_column module="page" translate="label">
<label>1 column</label>
<template>page/1column.phtml</template>
<layout_handle>page_one_column</layout_handle>
<is_default>1</is_default>
</one_column>
<full_column module="page" translate="label">
<label>Full 1 column</label>
<template>page/full1column.phtml</template>
<layout_handle>page_one_column_full</layout_handle>
<is_default>1</is_default>
</full_column>
<two_columns_left module="page" translate="label">
<label>2 columns with left bar</label>
<template>page/2columns-left.phtml</template>
<layout_handle>page_two_columns_left</layout_handle>
</two_columns_left>
<two_columns_right module="page" translate="label">
<label>2 columns with right bar</label>
<template>page/2columns-right.phtml</template>
<layout_handle>page_two_columns_right</layout_handle>
</two_columns_right>
<three_columns module="page" translate="label">
<label>3 columns</label>
<template>page/3columns.phtml</template>
<layout_handle>page_three_columns</layout_handle>
</three_columns>
</layouts>
Thanks!
Config.xml is just the configuration file of your module and it's not intended for (direct) layout updates. For this purpose you have to create one config.xml file for each module and, in this files, create the XML instructions, through XML node "updates", that say to magento "this is the path for the layout file of this module":
...
<frontend>
...
<layout>
<updates>
<(modulename)>
<file>(name_of_layout_file.xml)</
</(modulename)>
</updates>
</layout>
</frontend>
From: Frontend (Magento - Wiki - config.xml Reference)
Now, you have to create that file within the layout folder of your template, putting inside all the code you need to update the global layout.
More infos:
Adding Additional Layout XML Updates via Modules (Jan 2012; by Alan Storm)
Sorry it's been a while since I post this question. I have been in a vacation for the past weeks so I don't have time to visit this page.
I already figure out the solution for this kind of problem.
Every custom module that a developer will create should register it first to app/etc/modules folder.
Step 1: I followed the folder structure from the app/code/core and put it on the app/code/local. The structure goes like this app/code/local/Mage/Page/etc/config.xml
Step 2: To register my new modules. I Created an .xml file in app/etc/modules and name it any name I want.
Step 3: I open the .xml file I have created and add this piece of code
<?xml version="1.0"?>
<config>
<modules>
<Mage_Page><!-- <Mage_Page> tag came from two folders. Mage is my namespace from app/code/local/Mage and Page is my module name from app/code/local/Mage/Page. -->
<active>true</active>
<codePool>local</codePool>
</Mage_Page>
</modules>
</config>
Step 4: Save all the files you have created/updated.
Step 5: I refresh the admin page and checked if my work is working and yes it is working.
This took me a while due to lack of knowledge and experience in developing magento. But thanks for your help.
Thanks!
Related
I have successfuly made a custom tab with custom fields inside it following this tutorial: datasheat
However, I need the implementation to be on my own "module". Does any of you know how the catalog_product_new.xml and Tabs.php be implemented if ever I move them onto my own module directory? Sorry this is my first ever post and I am not sure if I should copy paste the long codes in my post but I'll do you needed.
THis is my first time to code in Magento as I do Opencart stuff, but was unfortunately tasked with porting an OC plugin to Magento.
Thanks guys!!!!
Namespace Name: Test
Module Name: ProductTabs
First go to the admin panel of your Magento store and then navigate to Stores -> Product. Click on Add New Attribute and create new Attribute. (Set Attribute label DEMO and Attribute code demo)
Now go to Stores -> Attribute Set and Add Attribute Set.
Now click on your Attribute Set and dragged unassigned Attribute (which you have created in first step) to Product Details and click Save.
Now go to your product edit page in admin panel and change the attribute name and template name which you have created in first and second step.
In app/code/Test/ProductTabs/etc/module.xml paste this code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_ProductTabs" setup_version="1.0.0"></module>
</config>
In app/code/Test/ProductTabs/registration.php, paste this code.
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_ProductTabs',
__DIR__
);
In app/code/Test/ProductTabs/view/frontend/layout/catalog_product_view.xml, paste this code.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_config uration.xsd">
<body>
<referenceBlock name="product.info.details">
<block class="Magento\Catalog\Block\Product\View" name="demo.tab" template="Test_ProductTabs::custom_tab.phtml" group="detailed_info" >
<arguments>
<argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Now in app/code/Test/ProductTabs/view/frontend/templates/custom_tab.phtml, paste this code.
<?php
$product = $block->getProduct();
?>
<h1 style="color: #00aeed"><?php echo $product->getData('demo'); ?></h1>
Now lauch your product page.
I created a new package/theme/skin from scratch in Magento 1.9.1.
The theme and skin load fine. I tried adding translations and cannot get them to load. All cache settings are disabled.
I've added the CSV file here:
/app/design/frontend/{my_package}/{my_theme}/locale/en_US/translate.csv
translate.csv:
"testing123","Translation Worked"
header.phtml
<?= $this->__('testing123') ?>
I added {my_theme}, which for me is named "responsive" to the admin at the :
The result is the header displaying 'testing123' instead of the translated 'Translation Worked'. What have I missed? How do I troubleshoot this?
Update:
I've also added translate.csv to config.xml (and it still does not work). However, It DOES work if I move the translate.csv to app/locale/en_US but it DOES NOT work in app/design/frontend/{my_package}/{my_theme}/locale/en_US/translate.csv where I want it. How can I tell it to load from the theme folder?
config.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyModule_Templates>
<version>0.1.0</version>
</MyModule_Templates>
</modules>
<frontend>
<translate>
<modules>
<MyModule_Templates>
<files>
<default>translate.csv</default>
</files>
</MyModule_Templates>
</modules>
</translate>
</frontend>
<global>
<page>
<layouts>
<mymodule_default translate="label">
<label>MyModule Default Layout</label>
<template>page/default.phtml</template>
<layout_handle>mymodule_default</layout_handle>
</mymodule_default>
</layouts>
</page>
</global>
</config>
Seems, You forgot to add translate.csv to your module's config.xml.
Please take a look.
http://inchoo.net/magento/how-to-add-your-own-translations-to-custom-modules/
i struggled with the same problem. Solution for me was to change the translation Source in the Admin Area.
Go to : Configuration -> select your Store view ( new Translation ) -> General -> under "options for localisation" uncheck the box and choose which translation you want to use. Afterwards, the translate.csv gets loaded and the translation works.
Cheers,
moktor
I was in the middle of writing some code for a Magento website, and I feel like I'm at odds with what I am trying to accomplish.
I am trying to write an extension which inserts 2 blocks:
Hello_Catalog_Block_Category_View: which overrides the Mage_Catalog_Block_Category_View Block with some extra functionality.
Hello_Catalog_Block_Custom: which is a customised class I want to create for this extension
Here's what I have tried to write in the config.xml file:
<blocks>
<catalog>
<rewrite>
<category_view>Hello_Catalog_Block_Category_View</category_view>
</rewrite>
<class>
<custom>Hello_Catalog_Block_Custom</custom>
</class>
</catalog>
</blocks>
Obvously if I tried this code when I refresh the browser, this doesn't work because I must have initialised the custom block the wrong way.
Now if I tried to write in this fashion:
<blocks>
<catalog>
<rewrite>
<category_view>Hello_Catalog_Block_Category_View</category_view>
</rewrite>
<class>Hello_Catalog_Block</class>
</catalog>
</blocks>
Now when I refresh the browser, the templates for Catalog Category view don't get rendered and I get the feeling it gets overridden by <class>Hello_Catalog_Block</class>.
My question is, is there a way to write an extension that allows these 2 blocks to be used or together or would it just be a case where either you write an extension that overrides blocks or you write an extension that creates new blocks only, not both?
Thanks.
I think there's a disconnect between what you think a "custom block" will do and what they actually do. There's no way to just add something to config.xml and have the block show up on the page.
If you want to create a custom block for your module, the first step is to configure a new top level section under blocks
<blocks>
<hello_catalog>
<class>Hello_Catalog_Block</class>
</hello_catalog>
</blocks>
The <hello_catalog> node is you block's group name. When you use the above configuration, you're telling Magento
Hey Magento, if you see a block in the hello_catalog group, it's class name should start with Hello_Catalog_Block.
With the above in place, you'll be able to do things in Magento's layout update XML files (the XML files in app/design) like this
<block type="hello_catalog/custom" name="me_custom_block" />
The above XML is creating a block of type hello_catalog/custom. That's a block in the hello_catalog group, with its class name being custom. Magento will translate this into the full class name Hello_Catalog_Block_Custom (using the information from config.xml for the base name, and then lead-word-casing custom.
I am having a difficult time getting the MVC structure set up for an admin module I am building for Magento. What I am hoping to do is correctly set up the design/adminhtml/layout/ppr_extension.xml to control the content of the page. So far I am loading the phtml and scripts from the IndexController :
$this->loadLayout();
$this->_setActiveMenu('ppr_menu/first_page');
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('ppr/ppr_1.phtml'));
$loadSimple = $this->getLayout()->getBlock('head')->addJs('ppr/load.simple.js');
$this->_addJs($loadSimple);
$this->renderLayout();
I want to load this from the config xml but for some reason I can not get this work. I imagine it has something to do with my package structure but I can not see it!
The template file exists in design/adminhtml/default/MyPackage/ppr_1.phtml
I tried adding this to the code/local/MyPackage/PPR/etc/config.xml
<adminhtml>
<menu> ... </menu>
<layout>
<updates>
<ppr_extension>
<file>ppr_extension.xml</file>
</ppr_extension>
</updates>
</layout>
</adminhtml>
That extension xml is in design/adminhtml/default/default/layout/ppr_extension.xml
I tried many things in here like :
<?xml version="1.0"?>
<layout version="0.1.0">
<ppr_adminhtml_ppr_index>
<reference name="head">
<action method="addJs"><script>script.js</script></action>
</reference>
No matter what I put in there nothing seems to happen. What am I missing?
I tried moving the extension.xml to design/adminhtml/MyPackage/layout but that didnt work either. Thanks for any help.. me brain hurts!
This should be easier now that you're using Commerce Bug.
The first step to debugging a layout problem is to make sure that your layout xml file is being loaded. Go to the layout tab in Commerce Bug and click on the Package Layout link. Look for your custom XML there. If you don't see it that means your XML isn't being loaded, and you should concentrate on getting the right XML in your config.xml, and getting your file in the right location.
Also, consider that the there's no need to use layout xml at all. The Admin Console developers use it for the outer shell and for some of the magic widget features, but there's a lot of stuff in the admin that's just blocks added in controller actions, or blocks added in other blocks. There's no shame in using PHP to generate your block objects.
I am creating a custom module where i added a button in product view page(default file).I have inserted the button code in the following file
app\design\frontend\base\default\template\catalog\product\view.phtml
and the button gets displayed & works well.But everytime Magento is updated , the above file gets replaced and so my code is discarded.Is there any way to modify or extend or inject the template coding from within my custom module?Should i need to override the core blocks or somehting?
Give your module a layout file:
...
<frontend>
<layout>
<updates>
<YOUR_MODULE>
<file>YOURMODULE.xml</file>
</YOUR_MODULE>
</updates>
</layout>
</frontend>
...
In the base theme's layout/YOURMODULE.xml file:
<layout version="1.0">
<catalog_product_view>
<reference name="product.info">
<action method="setTemplate"><name>YOURMODULE/product/view.phtml</name></action>
</reference>
</catalog_product_view>
</layout>
Copy the modified view.phtml to a new directory, template/YOURMODULE/product/
When packaging your module remember to include all these files but don't overwrite template/catalog/product/view.phtml.
Anyone downloading your module might want to make their own changes to that template so you should also include instructions on which file has been changed and where to find it. Since view.phtml is often changed by both themers and other modules it would be a much better idea to alter one of the child templates instead - which one depends on where your button will be.
As a bonus there is a block called extrahint just after the prices of type core/text_list - it doesn't have a template so you might normally miss it when using template path hints. You can safely add as many templates as you like to it without altering any existing ones:
<layout version="1.0">
<catalog_product_view>
<reference name="product.info.extrahint">
<block type="core/template" name="YOUR.CUSTOM.BLOCK" template="YOUR/CUSTOM/TEMPLATE.phtml" />
</reference>
</catalog_product_view>
</layout>
That only helps if just after the price is useful for you. Other blocks that can be safely appended are the options and containers areas, but they only show for products with options.
The problem is that you are installing it in app/design/frontend/base/default.
You need to create a copy of this directory in another directory, such as app/design/frontend/default/yoursite.
Read this for more info on how to do it specifically
You can't build your custom extension to be dependent on default views it shows bad planning. you should either clone this template or extend it and have ways to enable and disable your functionality. The must have thing is "designers guide" if your module implements templates or has ways to modify other templates.