I followed this tutorial to create the custom block in magento
http://www.gravitywell.co.uk/blog/post/how-to-creating-your-own-custom-block-in-magento
But nothing is showed when I open up home page or any other page. I have searched alot on web but unable to solve the issue.
The above tutorial did not mention where to create layout.xml file but I have created it at:
app\design\frontend\gravitywell\example\layout\layout.xml ---It has just following code:
<block type="gravitywellexample/menu" name="menu" as="menu" template="gravitywell/menu.phtml" />
Any help will be highly appreciated.
Thanks in advance.
I would use local.xml, but then the question becomes what handle tags to put it inside of i.e. where do you want it to show up. When using a 2column-right layout, I can position it inside of the right column on the product page this way:
<catalog_product_view>
<reference name="right">
<block type="gravitywellexample/menu" name="menu" as="menu" template="gravitywell/example/menu.phtml" />
</reference>
</catalog_product_view>
my template is stored in a slightly different folder.
hth, sconnie
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'm trying to remove "recently viewed" from the home page, but I don't know where the block is called. I tried to delete reports.xml but the block stayed there. Then I tried to delete all the code in home_product_viewed.phtml and it worked, but I don't want to delete the code. I only want to delete the call to that file but I don't know where that file is called.
Goto magento backend.
Select the CMS page for homepage.
In the Design section add the below code in the Layout Update XML field
<reference name="right">
<action method="unsetChild"><alias>right.reports.product.viewed</alias></action>
</reference>
To remove it from only the home page, I would do this. Go to your /app/design/frontend/packagename/themename/layout/local.xml
and edit it like this:
<layout>
<cms_index_index>
<remove name="right.reports.product.viewed" />
</cms_index_index>
</layout>
To verify your packagname and themename, go in to admin - System - Configuration - Design.
There may already be other code inside of the layout tag which you should leave there!
This worked for me -> Using left below not right.reports.product.viewed.
Custom Layout Update
<reference name="right">
<action method="unsetChild"><alias>left.reports.product.viewed</alias></action>
</reference>
I'm pretty new to Magento, and have been following the base theme so far along, but I am having problems with catalog pagination.
At the moment I'm having problems getting the "page/html_pager" block to display.
So, my catalog.xml has this for both anchor and non-anchor categories:
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager" />
</block>
</block>
</block>
</reference>
My toolbar.phtml has the corresponding code:
<?php echo $this->getPagerHtml() ?>
and my default/template/page/html/pager.phtml just contains some test code along the lines of:
<h1>Test</h1>
At first I thought it might be because there weren't multiple pages, so I added some products and set the both the grid and the list views to show a maximum of 1 per page, and the item count reflects this:
Showing 1 of 11 items
Doing a var_dump on the $this->getPagerHtml() returns an empty string, and using the template path hints indicates it doesn't even seem to load the block - yet it loads it's parent block.
Copying the code directly from the base design package doesn't work, yet switching to that package it does.
So, what am I missing? Or doing wrong? I've run out of ideas as to what it could be.
thanks
Solved:
Adding<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
After the product_list_toolbar block appeared to fix this issue.
Magento's documentation is a little thin on the ground with this so I'm unsure as to why
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
requires it's name set again with an action tag, but it does.
If anyone can explain this, I'd love to understand it.
Any chance that it's being overridden by a different .xml file in layout?
You could always remove all the .xml files in the layout directory and bring them back in one by one and see if the pagination toolbar disappears, whilst making sure cache is turned off.
After that, rename the template directory catalog to ~catalog and let it pick up the base catalog directory and see if it's actually the .phtml files causing the problem.
I am developing a new custom module in magento. I need to customize the shopping cart page without affecting the original cart.phtml. My module name is Stallioni. I have placed the cart.phtml inside frontend/default/default/template/stallioni/checkout/cart.phtml .How can i use this cart.phtml in my new module instead of the original . I know we should change something in checkout.XML or stallioni/layout/stallioni.xml file. But no idea since i am new.I googled out a day but couldn't find.
http://blog.chapagain.com.np/magento-overriding-template-file-from-custom-module/ this link tells something but it didn't worked for me.I need your help!
If your layout.xml is working add this code in your layout
`<checkout_cart_index>
<reference name="content">
<reference name="checkout.cart">
<action method="setTemplate">
<template>default/default/template/stallioni/checkout/cart.phtml</template>
</action>
</reference>
</reference>
</checkout_cart_index>`
It should work :)
I asked this question yesterday Static block on home page in Magento, which answered my question about hooking a cms/block to an existing block (content, in that example).
But now I would like to know how to create my own block.
I have this in my .phtml template:
<?php echo $this->getChildHtml('home_flash') ?>
And this in my cms.xml file
<reference name="home_flash">
<block type="cms/block" name="home-page-flash" before="content">
<action method="setBlockId"><block_id>home-page-flash</block_id></action>
</block>
</reference>
But this is not working.
I have also tried to create my own block type, (by copying the breadcrumbs declaration) in the page.xml file:
<block type="page/html_home_block" name="home_block" as="home_block" template="page/template/home_block.phtml"/>
That file exists but isn't being rendered.
However when I reference the block like this:
<block type="page/html_breadcrumbs" name="home_block" as="home_block" template="page/template/home_block.phtml"/>
It renders my home block template, but the original cms/block is not attached to it.
Hope all the different cases show what is happening and highlight the gap in my knowledge well enough for someone to answer, do I have to "register" my new "home_block" type somewhere?
There are many different blocks available that you can use without creating your own. In this case I think core/text_list would be suitable because it doesn't require a template and can have as many child blocks within it as you need.
<?xml version="1.0"?>
<layout version="0.1.0"><!-- All layout files start with this -->
<cms_index_index><!-- Index directive is the same as "home" page -->
<reference name="root"><!-- For more blocks that can be referenced see "default" directive -->
<block type="core/text_list" name="home_flash">
<block type="cms/block" name="home-page-flash">
<action method="setBlockId"><block_id>home-page-flash</block_id></action>
</block>
</block>
</reference>
</cms_index_index>
<!-- More directives might go here -->
</layout>
Other useful block types worth knowing are core/text and core/template which correspond to Mage_Core_Block_Text and Mage_Core_Block_Template respectively. They get used the most.
Your home made block type of page/html_home_block didn't have any PHP class with a matching name, and if you were genuinely creating your own you wouldn't be able to use the page prefix since Magento already does.
To create a block you only need a <block> tag in the layout file.
To create a block type you need to write a PHP class, give it a namespace and declare it as part of a module.
To add to an existing block is the time when you use a <reference> tag.
There are many fine articles at Magento Knowledge Base including some on Theming & Design.