Im looking for solution to define layout handle for whole controller insteat of controller_action. For example i want to define:
<mymodule_index></mymodule_index>
instead of
<mymodule_index_index></mymodule_index_index>
<mymodule_index_someaction></mumodule_index_someaction>
Thanks.
You can add a layout handle by running this :
$update = $this->getLayout()->getUpdate();
$update->addHandle('mymodule_index')
You can then add this piece of code to a protected "_initHandles" function within your controller that you would run for every action.
In my controller I've (re)implemented this method
public function loadLayout($handles = null, $generateBlocks = true, $generateXml = true)
{
return parent::loadLayout(array('default','mymodule_index'),$generateBlocks,$generateXml);
}
which will add an update handle called mymodule_index (not loosing the default one) for every controller's action.
You'll need to call loadLayout() in every controller's action, but that's how magento works...
please try below code....
public function indexAction(){
{
...
$update = $this->getLayout()->getUpdate();
$update->addHandle('mymodule_index');
$this->loadLayoutUpdates();
$this->generateLayoutXml()->generateLayoutBlocks();
$this->renderLayout();
}
public function samelocationAction(){
{
...
$update = $this->getLayout()->getUpdate();
$update->addHandle('mymodule_index');
$this->loadLayoutUpdates();
$this->generateLayoutXml()->generateLayoutBlocks();
$this->renderLayout();
}
I've found solution. In each next update you must provide <update handle="" /> like this:
<companies_catalog>
<label>Companies (All Pages)</label>
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
<reference name="left">
<block type="businesscategory/companies_navigation" name="companies.navigation" before="-" template="businesscategory/companies/navigation.phtml" />
</reference>
</companies_catalog>
<companies_catalog_index>
<label>Companies (All Pages)</label>
<update handle="companies_catalog" />
<reference name="content">
<block type="businesscategory/companies_list" name="companies.list" template="businesscategory/companies/list.phtml" />
</reference>
</companies_catalog_index>
<companies_catalog_view>
<label>Company page</label>
<update handle="companies_catalog" />
<reference name="content">
<block type="businesscategory/companies_view" name="company.info" template="businesscategory/companies/view.phtml" />
</reference>
</companies_catalog_view>
Related
I have a Magento store with two separate headers. Let's say out of 20 pages 15 use header.phtml and 5 use headerGreen.phtml. I've already created my custom layout module however I can't seem to get the new header to appear on select pages. The new headerGreen.phtml file has been created as well. The issue lies when I try to call the new header in the newly created layout page.
<?php echo $this->getChildHtml('headerGreen') ?>
I dont think I've added it correctly to the local.xml and was hoping someone could help.
<default>
<reference name="header">
<block type="core/template" name="header" template="page/headerGreen.phtml" />
</reference>
</default>
The function getChildHtml is expecting you to send a name of a child in the layout as first parameter
app/code/core/Mage/Core/Block/Abstract.php defines it :
/**
* Retrieve child block HTML
*
* #param string $name
* #param boolean $useCache
* #param boolean $sorted
* #return string
*/
public function getChildHtml($name = '', $useCache = true, $sorted = false)
{
// the code is does not really matter here
}
So based on your layout you should actually do
<?php echo $this->getChildHtml('header') ?>
Because header is the name attribute in this xml node of your layout :
<block type="core/template" name="header" template="page/headerGreen.phtml" />
As said in the comments, your layout is also looking strange because you are actually telling that your new header is going to be a child of the current header.
Two thinks you can do :
Use the powerfulness of the action nodes :
<default>
<reference name="header">
<action method="setTemplate">
<template>page/headerGreen.phtml</template>
</action>
</reference>
</default>
Or redefine the whole header block
<default>
<reference name="root">
<block type="core/template" name="header" as="header" template="page/headerGreen.phtml" />
</reference>
</default>
I want to specify multiple values for ifconfig in layout xml.
<action method="setTemplate" ifconfig="mymodule/general/is_enabled">
<template>mymodule/test.phtml</template>
</action>
Is is possible to add below two conditions for one action?
ifconfig="mymodule/general/is_enabled"
ifconfig="mymodule/frontend/can_show"
Any suggestions would be most welcome.
You could use a helper method in your action parameter. Something like this
<action method="setTemplate">
<template helper="mymodule/myhelper/canShowIf"/>
</action>
will call setTemplate with the results of a call to
Mage::helper('mymodule/myhelper')->canShowIf();
And the following in your modules default helper:
public function canShowIf()
{
if($displayOnly = Mage::getStoreConfig('mymodule/general/is_enabled') == true)
// Do Something
}else if($displayOnly = Mage::getStoreConfig('mymodule/frontend/can_show') == true) {
// Do Something Else
}
return $displayOnly;
}
Implement your custom logic in canShowIf.
Define a function in Helper (Data.php)
<reference name="root">
<action method="setTemplate">
<template helper="modulename/getNewLayoutupdate"/>
</action>
</reference>
in helper function you can load template by conditions.
consider below scenario:
<catalog_category_default>
<reference name="product_list">
<action method="setTemplate" >
<template>mymodule/mytemplate.phtml</template>
</action>
</reference>
</catalog_category_default>
ifconfig : If return value is false, then it takes layout defined in base folder.
helper function : If return value is false, then does not take layout defined in base folder, and not template gets added. that's why empty block is shown.
ifconfig="mymodule/general/is_enabled"
ifconfig="mymodule/frontend/can_show"
why not create an additional config node
ifconfig="mymodule/frontend/is_enabled_can_show" and depending on this value proceed.
We redesign a magento shop. That shop had a very costumized searchresult page.
Now, after the redesign, the search does not work anymore.
I broke down the problem to the List.php (Mage\Catalog\Block\Product\List.php) where the function _getProductCollection() is called to get the results. This function gets a layer $layer = $this->getLayer(); and there is the main difference to the old version:
public function getLayer()
{
$layer = Mage::registry('current_layer');
if ($layer) {
return $layer;
}
return Mage::getSingleton('catalog/layer');
}
In the old version the Mage::registry('current_layer'); is set. In the new version its not set! And when it is not set it returns a new one return Mage::getSingleton('catalog/layer'); with all the products in it.
I can't think any further. How could I find the place where this layer is set in the old version?
What else could I do?
The search layer model is registered by the catalogsearch/layer block, which is usually added to the search page by the catalogsearch.xml layout file :
<catalogsearch_result_index translate="label">
<label>Quick Search Form</label>
<reference name="root">
<action method="setTemplate"><template>page/3columns.phtml</template></action>
</reference>
<reference name="left">
<block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
<!-- ... -->
</catalogsearch_result_index>
As it has certainly gone missing, you should add it back to your layout.
<?php
class Excellence_Manager_Adminhtml_ManagerController extends Mage_Adminhtml_Controller_action
{
public function customerAction(){
$this->loadLayout();
$this->getLayout()->getBlock('customer.grid')
->setCustomers($this->getRequest()->getPost('customers', null));
$this->renderLayout();
}
I am following this grid serializer tute . I just can not understand where is this setCustomers coming from ?
Even in other tutes I saw that setClent(), setDog() etc. But where is get or it's not from the database either. not in the layout either I think. Please help thanks.
<manager_adminhtml_manager_customer>
<block type="core/text_list" name="root" output="toHtml">
<block type="manager/adminhtml_manager_edit_tab_grid" name="customer.grid"/>
<block type="adminhtml/widget_grid_serializer" name="grid_serializer">
<reference name="grid_serializer">
<action method="initSerializerBlock">
<grid_block_name>customer.grid</grid_block_name>
<data_callback>getSelectedCustomers</data_callback>
<hidden_input_name>links[customers]</hidden_input_name>
<reload_param_name>customers</reload_param_name>
</action>
<action method="addColumnInputName">
<input_name>position</input_name>
</action>
</reference>
</block>
</block>
I found it's not from hidden_input_name or reload_param_name.
__set() is run when writing data to inaccessible properties.
__get() is utilized for reading data from inaccessible properties.
Magento implements so called "Magic Methods" to set data in an object.
They implemented __set and __get which are called, when no method for e.g. setCustomers() is found, and use those methods to do setData('customers', "YOUR_VALUE");
I use this tutorial and display products on the basis of multiple categories but now I am getting in issue is that the pager tool bar not working on that.
My block code is :
<reference name="content">
<block name="mymodule" type="mymodule/product_listcategories" template="catalog/product/list.phtml">
<action method="setCategories">
<ids>2,3,4</ids>
</action>
</block>
</reference>
I also add this code with above
<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>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
It display toolbar but the toolbar is not working (limit,orderby).
My block code is
class Mymodule_Block_Product_Listcategories extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
$this->_productCollection = Mage::getModel('catalog/product')->getCollection();
$this->_productCollection->addAttributeToSelect('*');
if($this->getCategories()!="")
$this->_productCollection->addCategoriesFilter($this->getCategories());
return $this->_productCollection;
}
}
}
Does anyone know where is the problem? I think I'm missing some code for the pager? Thanks in advance
After search so much i got a solution.I didn't know whether it right or wrong way but it solve my problem.On my block i create intance of
$cpBlock = $this->getLayout()->getBlockSingleton('Mage_Catalog_Block_Product_List_Toolbar');
and access the pager core function like $this->_itemPerPage = $cpBlock->getLimit(); .In the above code itemperpage is the total no of items to be displayed on listing page.This code work if you create custom module and extend you block from list block.Thanks