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.
Related
I've built a custom shopping cart for my Magento site that sends and API call to Shopify to handle payment.
The problem is I need the template file to load on every page in magento. I thought after_body_start would be a good place to put the template, but I cannot get it to load!
My template lives in \app\design\frontend\rwd\crystal\template\mgw\mwCart.phtml
and contains php, html and javascript. It was running just fine when I placed the code directly into the header.phtml
Here's the xml in \app\design\frontend\rwd\crystal\layout\local.xml which should load the template
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="after_body_start">
<block type="core/template" name="mwCart" template="mgw/mwCart.phtml" output="toHtml" before="-" />
</reference>
</default>
</layout>
I'm new to Magento and have read through the tutorials. I also checked out and tried any suggestions I could find.
I've seen this Magento - Add Some HTML on All Pages of my Theme After_Body_Start but did not solve my issue.
How can I get my template to load on every page?
Thank you.
You're close here... It the location of your local.xml file that is the problem. Place the existing file in the following location:
app/design/frontend/rwd/default/layout/local.xml
..and it should solve the problem. If you have an existing subtheme, e.g. rwd/mytheme, the file would go here:
app/design/frontend/rwd/mytheme/layout/local.xml
If you still aren't getting the desired results, check the configuration in Magento Admin->Configuration->Design->Themes and make sure that you are indeed using the rwd theme. If all else fails, the base/default location would be the last thing to try:
app/design/frontend/base/default/layout/local.xml
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!
I’m having trouble in moving the mini cart from sidebar to header. I’ve tried all the tutorials available in the internet but it doesn’t work.
I also tried adding this in the header block of layout\page.xml
<block type="checkout/cart_sidebar" name="cart_sidebar" as="topcart" template="checkout/cart/sidebar.phtml"
And then in my page\html\header.phtml, I use the code below to call the cart but nothing happened.
<?php echo $this->getChildHtml('topcart'); ?>
The solution above works in magento 1.6, but not in version 1.7
First you need to create or update your local.xml file IF you do not have a local.xml file you can create one in
app->frontend->[Package Name]->[Theme Name]->layout->local.xml
Once this is created you can copy exactly what I have in this post into that file for a start of how to use one.
DO ALL UPDATES THROUGH A LOCAL.XML file not through catalog.xml or checkout.xml !! This will make upgrades significantly easier later down the road. Additionally, you will be able to quickly see all changes you have made to your site in one file.
The below example will add it to the header reference name which will be available on all pages as indicated by the tag and will only be available in the header.phtml file. Duplicate base/default/checkout/cart/sidebar.phtml and rebane that file as topcart.phtml and place it into your theme at [Your Package]/[Your Theme]/template/checkout/cart/topcart.phtml by doing this you are cloning the sidebar functionality and adding it to the header. Then you can make any edits through the topcart.phtml file without affecting base functionality.
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="header">
<block type="checkout/cart_sidebar" name="topcart_mini" as="topcart" template="checkout/cart/topcart.phtml" />
</reference>
</default>
</layout>
Then call it in header.phtml with
<?php echo $this->getChildHtml('topcart'); ?>
This is the proper way to modify Magento, this makes upgrades quite simple. Additionally, it does not edit any core files.
Insteat of copying block xml, you should reference it like
<reference name="block-name">
</reference>
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 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.