struggling getting access to an admin block ive created.
Ive created a module...it has many elements, all working. Ive got header includes added to certain admin pages no problem, using my adminhtml layout update xml file.
The issue seems to be it cant access/see my block...so muct be referencing wrong, even though ive been following the 'module creator' extension files.
Another silly issue i think, been at this too long! :)
First the code:
Mworkz/MyModuleName/Block/Adminhtml/MyBlock.php
class Mworkz_MyModuleName_Block_Adminhtml_MyModuleName extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
var_dump('WE ARE IN THE ADMIN BLOCK!');exit;
$this->_controller = 'adminhtml_mymodulename';
$this->_blockGroup = 'mymodulename';
$this->_headerText = Mage::helper('mymodulename')->__('Item Manager');
$this->_addButtonLabel = Mage::helper('mymodulename')->__('Add Item');
parent::__construct();
}
}
My layout xml (this file works, and is referenced right, as my admin header includes work)
Should point out i have a custom tab and controller...all working.
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodulename_adminhtml_mymodulename_index>
<reference name="head">
<action method="addJs"><script>Mworkz/MyModuleName.js</script></action>
</reference>
<reference name="content">
<block type="mymodulename/adminhtml_mymodulename" name="mymodulename" ></block>
</reference>
</mymodulename_adminhtml_mymodulename_index>
</layout>
I expect to see the var_dump stmt ive inserted....but it doesnt display.
Thanks in advance...
file naming! Simple caps issue...
My block file was called '...Adminhtml/MyModuleName.php',
My block identifier inside the file was '...Adminhtml_Mymodulename {'
Another set of working code snippets for adminhtml block users i suppose!
Thanks
Related
I have add a body class to default layout (local.xml) and I want to remove it in some specific area. Tried to use removeBodyClass but Magento 1.7.0.2 shows me an error "Invalid method Mage_Page_Block_Html::removeBodyClass(Array..."
How to solve that?
addBodyClass is working, removeBodyClass cause problems. Please give me a solution. Thanks in Advance
<layout>
<default>
<reference name="root">
<action method="addBodyClass"><classname>halloweenClass</classname></action>
</reference>
</default>
</layout>
There are no class exits on removeBodyClass in magento CE 1.7.
and if want to do this then rewrite Mage_Page_Block_Html class then add function removeBodyClass
public function removeBodyClass($className)
{
$className = preg_replace('#[^a-z0-9]+#', '-', strtolower($className));
$this->setBodyClass(str_replace($className,' ',$this->getBodyClass()). ' ' . $className);
return $this;
}
I am creating a module that will have its own page at mysite.com/memymodule/index/index
I want to add functionality from a template file from at templates/me/template.phtml
I have an index controller like this:
<?php
class me_mymodule_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
?>
I have a layout update mymodule.xml that looks like this:
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_index_index>
<reference name="content">
<block type="core/template" name="me.mymodule" template="me/template.phtml" />
</reference>
</mymodule_index_index>
</layout>
The frontName of the module is mymodule
When the page renders the content block is completely empty and the content of template.phtml is completely ignored.
Help much appreciated :-)
Try this Code within your Controller's Action -
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
exit("Your Layout Path is ".__LINE__." in ".__FILE__);
This code tells you about the Tag which you need to create within Layout.xml.
Also check Config.xml that the Layout Update Section is correctly defined or not.
Hope it'll be beneficial for you.
THANKS
I am showing only a single product on home page. I want to show the product name in page title. How can I do this?
You have multiple ways of doing this:
In your module's layout xml file (located at app/design/frontend/[package]/[theme]/layout/{your_file_name}.xml):
<reference name="head">
<action method="setTitle"><title>Title text here</title></action>
</reference>
The bad thing here is that you can't set tittle "on the fly".
In your block file (_prepareLayout() method is a good place):
public function _prepareLayout()
{
$headBlock = $this->getLayout()->getBlock('head');
$headBlock->setTitle('Title text here');
return parent::_prepareLayout();
}
Anywhere else:
Mage::app()->getLayout()->getBlock('head')->setTitle('Title text here');
Useful link - Layouts, Blocks and Templates
I have successfully install magento, but site title remain magento, I try many times but did not change that title?and did not change thing under the widget? so what is the procedures?
you can do it via layout files:
<reference name="head">
<action method="setTitle" translate="title"><title>Your Title</title></action>
</reference>
or via code by accessing head block element and calling setTitle('your title') method on it
$this->getLayout()->getBlock('head')->setTitle('your title');
grep for more references:
grep '>setTitle(' app/code/ -rsn
Put this function in Block page of that Module
public function _prepareLayout()
{
$this->pageConfig->getTitle()->set(__('Your Page Title'));
return parent::_prepareLayout();
}
I would like to create a link on the My Account page that only get displays under certain conditions.
Right now I have the link display all the time by adding the following entry to my layout XML file:
<customer_account>
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="nie"><name>nie</name><path>nie</path><label>NIE Admin</label></action>
</reference>
</customer_account>
I am assuming there is a way to code this so that it only displays under certain circumstances.
The cart & checkout links already do something similar so their method can be copied.
Create a block. It won't be displaying directly so can be descended from the boring Mage_Core_Block_Abstract.
Give it a method where the conditional logic will go.
public function addNieLink()
{
if (($parentBlock = $this->getParentBlock()) && (CONDITION-GOES-HERE)) {
$parentBlock->addLink($this->_('NIE Admin'), 'nie', $this->_('NIE Admin'), true, array(), 50, null, 'class="top-link-cart"');
// see Mage_Page_Block_Template_Links::addLink()
}
}
protected function _prepareLayout()
{
// Add the special link automatically
$this->addNieLink();
return parent::_prepareLayout();
}
Put your check in place of CONDITION-GOES-HERE.
Add your block to the links block.
<customer_account>
<reference name="customer_account_navigation">
<block type="yourmodule/link" name="yourmodule.link" />
</reference>
</customer_account>
(Correct the block type here to your newly created link block)
The important bit is it calls getParentBlock() to find out where the link is to go.