I am including a new template for the layout menu with this in the config.xml :
<layouts>
<new module="page" translate="label">
<label>Foo</label>
<template>page/foo.phtml</template>
<layout_handle>page_foo</layout_handle>
</new>
</layouts>
This all works fine and then from admin I can go to Category->Custom Design and Foo will be a choice in the dropdown for Page Layout.
My problem lies in the foo.phtml which is in the page directory
In that file the footer for example is included with
<?php echo $this->getChildHtml('footer') ?>
if add another file in the same place as the footer.phtml, say bar.phtml in /page/html/ directory. Then I would expect to be able to include it the same way. When I do :
<?php echo $this->getChildHtml('bar') ?>
It does not show up. I imagine I must have to declare the bar file somewhere in the xml too? I want the bar file only to be included when someone chooses the foo layout option for a category. What am I missing?
The layout_handle node in your config refers to a node it expects to find inside one of your layout files. You can find examples of the other page layouts in app/design/base/default/layout/page.xml. But essentially you're going to want something along the lines of...
<layout>
<page_foo translate="label">
<reference name="root">
<block type="core/template" template="some/file.phtml" name="my_block" as="bar" />
</reference>
</page_foo>
</layout>
Related
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>
Is it possible to add the search box within the 3columns.phtml (like my categories.)
So for example i’d like to have on my products page on the left side:
So in the 3columns.phtml I have this line , the left div.
<div class="col-left sidebar"><?php echo $this->getChildHtml('left') ?></div>
So *what kind of code and where should I include In order that the search box appears on the left ?*
Any suggestion?
This is a good use for the file local.xml in your design layout folder. If you haven't created one yet, it goes:
/app/design/frontend/your_package/your_theme/layout/local.xml
local.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="left">
<block type="core/template" name="searchbox" template="path/to/searchbox.phtml" after="sibling.blockName"/>
</reference>
</default>
</layout>
Refresh your cache and that should work on all pages set to have the left column.
Explanation
This is one of the few methods that Magento has built in to load layout blocks. The first couple of tags are required on all layout files, <default> marks the update handle to apply to all pages. <reference name="left"> means we are altering the left bar, "left" being its block name. Now lets look at the block below:
type="core/template" - This type signifies which classes to use, as tied to app/code/core/Mage/* typically, but can be overwritten by copying the class files over to the app/code/local/Mage/* directory, as well as signifying classes of extensions like app/code/community/another_extension.
name="searchbox" - This is the name it will be referenced by in the layout. You can give it something else, but make sure it doesn't conflict with existing block names.
template="path/to/searchbox" - This is where you enter the path to the template file that will be loaded.
after="sibling.blockName" - This marks where to place it in the layout order. This only really needs to be set when the parent block (in this case, the referenced "left" block) is basically set to <?php echo $this->getChildHtml(''); ?>. No arguments in the ('') means it will load all child blocks in order as the xml defines.
In the case of <?php echo $this->getChildHtml('left') ?>, it's calling up the block that has the name="left". After giving it a name, you can alternatively give it another alias by using as="search.box.alias" within the <block /> tag, search.box.alias also being anything you want, provided it doesn't cause any conflicts.
Is there a way I could load filter layer state on the content area just below the page title
I've tried several ways like including template/catalog/layer/state.phtml into template/catalog/product/list.phtml, adding below snippet on <reference name="content"> on catalog.xml
<block type="catalog/layer_view" name="catalog.leftnav" after="leftnav" template="catalog/layer/view.phtml"/>
nothing works... what should I do?
thanks before :)
Here is quick fix: paste this in catalog/product/list.phtml
<?php echo $this->getLayout()->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state.phtml')->toHtml(); ?>
In page.xml search <block type="core/text_list" name="content" as="content" translate="label">:
Paste this code here (drawback: it will load in every content, will be better to find putting it within catalog pages block tag):
<block type="catalog/layer_state" name="catalog.layer.state" as="catalog.layer.state" template="catalog/layer/state.phtml"/>
Now incatalog/product/list.phtml file you can get this by:
<?php echo $this->getChildHtml('catalog.layer.state') ?>
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.
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.