Understanding Magento Adminhtml Layouts - magento

I am trying to load a custom layout page for my custom admin page "devices". Its not working ! :)
<layout version="0.1.0">
<adminhtml_devices_index_index>
<reference name="content">
<block type="adminhtml/template" name="index" output="toHtml" template="devices/index.phtml"/>
</reference>
</adminhtml_devices_index_index>
</layout>
If this is the XML in my app/design/adminhtml/default/default/layout/devices.xml
What are the different files/attributes I must be aware of ?
Also, what does type='adminhtml/template' actually point to ?
Note: My Controller code is
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}

For a quick test, use a non-template block. The block is going to be output as a course of rendering in the "content" block, so no need to specify output="toHtml".
<reference name="content">
<block type="core/text" name="devices.test">
<action method="setText">
<val>This is some sample text</val>
</action>
</block>
</reference>
The block type argument adminhtml/template points to the block class group "adminhtml", which is defined in Mage_Adminhtml config.xml:
<global>
<blocks>
<adminhtml>
<class>Mage_Adminhtml_Block
Based on this, the adminhtml/template argument points to the block name Mage_Adminhtml_Block_Template.

Try it:
<layout version="0.1.0">
<devices_adminhtml_index_index>
<reference name="content">
<block type="adminhtml/template" name="index" output="toHtml" template="devices/index.phtml"/>
</reference>
</devices_adminhtml_index_index>
</layout>
And I not sure what here should be: adminhtml/template Try replace it with core/template

Related

Remove canonical link in Magento 1.9.3.x

I want to remove the canonical link from a html page (Site Map).
<link rel="canonical" href="https://www.example.com/seositemap">
I used the following code in a layout and it does not work
<?xml version="1.0"?>
<layout version="0.1.0">
<seositemap_index_index>
<reference name="content">
<block type="seositemap/map" name="map" template="seositemap/map.phtml"/>
</reference>
<reference name="head">
<action method="removeItem"><type>link_rel</type><rel>canonical</rel></action>
</reference>
</seositemap_index_index>
</layout>
Any idea ?
here is how the method looks like
public function removeItem($type, $name)
{
unset($this->_data['items'][$type.'/'.$name]);
return $this;
}
there is no rel parameter. You should use "name" instead. And its content has to be the href of current link

Nested block and getChildHtml() in magento

I have some trouble when i get data with function getChildHtml() .
Here is my layout.xml file
<?xml version="1.0"?>
<layout version="0.1.0">
<hello_index_index>
<reference name="content">
<block type="hello/hello" name="title" template="hello/title.phtml">
<block type="hello/hello" name="title1" template="hello/title1.phtml">
<block type="hello/hello" name="title2" template="hello/title2.phtml"/>
</block>
</block>
</reference>
</hello_index_index>
</layout>
when i try print data in file title2.phtml to the screen with code is
echo $this->getChildHtml('title2');
OR
echo $this->getChildHtml('title1');
In the first way is no data displayed on the screen .
In the second way have data displayed on the screen but only data in file title1.phtml .
So how to display the data in file title2.phtml
Thank everybody .
As your code example is somewhat obscured, it's difficult for me to understand what your blocks actually are and/or do.
Remove the association between "title1" and "title2", then try rendering your block(s) with getChildHtml again.
<?xml version="1.0"?>
<layout version="0.1.0">
<hello_index_index>
<reference name="content">
<block name="title" template="hello/title.phtml" type="hello/hello">
<block name="title1" template="hello/title1.phtml" type="hello/hello" />
<block name="title2" template="hello/title2.phtml" type="hello/hello" />
</block>
</reference>
</hello_index_index>
</layout>
<block type="hello/hello" name="title" template="hello/title.phtml">
<block type="hello/hello" name="title1" template="hello/title1.phtml">
<block type="hello/hello" name="title2" template="hello/title2.phtml"/>
</block>
</block>
in title.phtml write $this->getChildHtml('title1'); and in title1.phtml write
$this->getChildHtml('title2')
because magento blocks can render only "child" blocks when using "getChildHtml()"

Magento, Static Block won't render?

this is my local.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/text_list" name="banner" as="banner" translate="label">
<label>Banner Area</label>
</block>
</reference>
<reference name="bannerblock">
<block type="core/template" name="bannerblock" template="banner.phtml" />
</reference>
</default>
</layout>
this is my 1column.phtml
<?php echo $this->getChildHtml('banner') ?>
I am not sure why it is not rendered. I think it might have to do with the placement of banner.phtml
should I put in
app/design/frontend/x/x/template/
or inside
app/design/frontend/x/x/template/page/html/
how do magenta find out?
You are referencing "bannerblock" block from inside of "bannerblock". Try moving the "bannerblock" block delaration into the "root" reference node:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/text_list" name="banner" as="banner" translate="label">
<label>Banner Area</label>
</block>
<block type="core/template" name="bannerblock" template="banner.phtml" />
</reference>
</default>
</layout>

magento - adding a block using local.xml

if I have a template in
app\design\frontend\base\default\template\dir\template.phtml
that look like this
<div class='block block-list'>
<div class='block-title'><strong><span>Some Block</span></strong></div>
<div class='block-content'>
<?php echo "my content"; ?>
</div>
</div>
How can I show it on a catalog page using local.xml? Shouldn't this code work?
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="right">
<block type="core/template"
name="somename"
template="dir/template.phtml" />
</reference>
</default>
</layout>
I think you can not have custom layout handle<catalog_category_default translate="label"> inside default layout handle<default>
Correct me if I am wrong.
You have to use template reference name before that reference tag.
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<catalog_category_default translate="label">
<reference name="right">
<block type="core/template"
name="somename"
template="dir/template.phtml" />
</reference>
</catalog_category_default>
</default>
</layout>

Why is my block not showing?

I don't know why my block isn't showing up. It's not showing up on any page, and I cleared the cache. Can someone help me figure out what I missed? However, the var_dump('test') shows up!
app/design/frontend/default/default/template/justin/head.phtml
testing this block
Justin/Bieber/Block/Sings.php
class Justin_Bieber_Block_Sings extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
var_dump("test");
}
}
config.xml
<frontend>
...
<layout>
<updates>
<bieber>
<file>justin.xml</file>
</bieber>
</updates>
</layout>
</frontend>
<global>
<blocks>
<bieber>
<class>Justin_Bieber_Block</class>
</bieber>
</blocks>
...
</global>
app/design/frontend/default/default/layout/justin.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/bieber" name="justin_bieber">
<action method="setTemplate">
<template>justin/head.phtml</template>
</action>
</block>
</reference>
</default>
</layout>
In your justin.xml block type should be
<block type="bieber/sings" name="justin_bieber">
In this case "bieber" is your module alias name and "sings" is class name.
Your code seems fine to me.
Regarding justin.xml try to change it to the following:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/sings" name="justin_bieber" as="justin_bieber" template="justin/head.phtml" />
</reference>
</default>
</layout>
Let me know if that works!
Symlinks were the problem. Magento won't be able to grab the file if it is in a symlinked directory.
Turn it on!
Magento/Zend not allowing symbolic links
Another thing is to turn on template hints!

Resources