I am trying to change Top links structure. I don't want to mess with xml files in default theme. I have only one xml file with everything inside. I don't want to create multiple xml files in my theme layout folder. I am trying to unset action inside top.links block.
This is the way I am trying to do:
<reference name="top.links">
<action method="unsetChild"><child>addLink</child></action>
<!-- <remove name="checkout_cart_link" /> -->
</reference>
When I put remove tag it works perfectly. But when I try to do unsetChild for addLink action it doesn't work. Do you know maybe how I should figure this out. I don't want separate xml files with the same names as in default theme.
The unsetChild function is from the Abstract block model and is used for removing a block that is a child of the current block. The block with the name top.links doesn't have a child block that is called addLink, hence the fact your configuration doesn't do anything. The action nodes with the method addLink call the addLink function on the Mage_Page_Block_Template_Links block. If the objective is to remove one of the links, you will need to use the action removeLinkByUrl.
<reference name="top.links">
<action method="removeLinkByUrl"><url>link/here</url></action>
</reference>
The exact arguments will obviously depend on what link you are attempting to remove.
Related
I am stuck a little with following problem:
I created a Fom in the adminhtml area using the pure php from Magento and standard template.
This all works as expected, but I cannot dynamically add and remove fields, I need Javascript and my own phtml file for that.
My Idea now was to simply include a childblock which is using a custom template at the end of the form.
So far I have added
$cblock =$this->getLayout()
->createBlock('netcon_konmod/adminhtml_caps_edit_mat')
->setTemplate('netcon_konmod_mat.phtml');
$this->_addContent($this->getLayout()
->createBlock('netcon_konmod/adminhtml_caps_edit')->setChild($cblock));
to my controller, created an empty Netcon_Konmod_Block_Adminhtml_Caps_Edit_Mat class which extends Mage_Adminhtml_Block_Widget
and created template file mat.phtml in .../template/netcon/konmod/
I also have my konmod.xml which updates my layout and which includes
<adminhtml_caps_edit>
<reference name="content">
<block type="netcon_konmod/adminhtml_caps_edit" name="netcon_konmod_caps_edit">
<block type="netcon_konmod/adminhtml_caps_edit_mat" name="netcon_konmod_caps_mat" template="netcon_konmod_mat.phtml" />
</block>
</reference>
</adminhtml_caps_edit>
I am rather new to Magento, and until now I only found ways to include a child block by calling getChildHtml from an already existing phtml file of the parent block.
However, since I create my form completely with the form and fieldset methods, I don't have my own phtml file in which I could include that call.
The way I have it set up right now, it is displaying the form normally, but does not include the childblock.
Any help would be appreciated, if it is at all possible to do this, I would like to avoid recoding my whole form as template.
Try
$childBlock = $this->getLayout()
->createBlock('konmod/adminhtml_caps_edit_mat')
->setTemplate('netcon_konmod_mat.phtml');
$this->_addContent($this->getLayout()
->createBlock('konmod/adminhtml_caps_edit')
//->setTemplate('netcon_konmod_mat.phtml')
->append($childBlock));
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.
Hi,
I am writing a Magento module. For that I want to call a core block inside my module's handler. I don't want to modify or extend the core block. I just want to call it inside my layout handler. Any suggestions?
The block I want to insert is located in
adminhtml/sales/order/view/history.php
Following handler is in the sales.xml which contains the above Histrory.php block
<adminhtml_sales_order_addcomment>
<block type="adminhtml/sales_order_view_history" name="order_history" template="sales/order/view/history.phtml" output="toHtml"/>
</adminhtml_sales_order_addcomment>
This is my layout.xml
<orderadmin_adminhtml_orderadmin_search>
<update handle="orderadmin_orderadmin_search" />
<reference name="content">
<!-- I want to insert the following block -->
<block type="adminhtml/sales_order_view_history" name="order_history" template="sales/order/view/history.phtml" output="toHtml"/>
</reference>
</orderadmin_adminhtml_orderadmin_search>
But it causes the following error.
Fatal error: Call to a member function getId() on a non-object in \app\code\core\Mage\Adminhtml\Block\Sales\Order\View\History.php on line 79
The issue is nothing to do the with xml layout, that is infact correct and will work as it is.
the issue is because this block is expecting an order to be in the registry, to enable it to grab the history.
You should set an order (the order you wish to use for viewing history) in the registry inside either your controller, or your modules block before the history block is rendered.
// load your order here..
Mage::register('sales_order', $order);
You have to do like this in your code :
<!-- this is my handler -->
<orderadmin_adminhtml_orderadmin_search>
<update handle="orderadmin_orderadmin_search" />
<reference name="content">
<block type="orderadmin/adminhtml_search" name="search_order" />
<!-- I want to call the core block here -->
Pick up from core layouts the block you wanted and paste here as it
is, it will get rendered
</reference>
</orderadmin_adminhtml_orderadmin_search>
I have a small custom module which is supposed to show on all product pages, but it doesn't. It only shows when setting its reference to "content", but I want it to display witin the already existing product view divs, thus, display it within the "product.info" reference.
Here's my code:
app/design/frontend/default/company/layout/company/socialbuttons.xml
<?xml version="1.0"?>
<layout>
<catalog_product_view>
<reference name="product.info">
<block type="core/template" name="company_socialbuttons" template="company/socialbuttons.phtml" />
</reference>
</catalog_product_view>
</layout>
I've spent hours finding the error, without success and if I can't find a solution soon I will do it the ugly way (calling the phtml inside the parent phtml). What am I doing wrong?
product.info handle is an instance of catalog/product_view block, and content is an instance of core/text_list block. The latter block is rendering every child block, even if there is no call to getChildHtml() method in the template.
So, if you want to add your block to product.info, you should call getChildHtml() method in the template.
Or, you can try reference of another blocks in product.info block: alert.urls or product.info.extrahint
If directly referencing the product.info block then you will have to use a call to getChildHtml() in your product view template:
echo $this->getChildHtml('company_socialbuttons');
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.