magento函数getChildHtml() 与getChildChildHtml() 的用法

  1. getChildHtml(‘a‘) //加载as=‘a’的block
  2. getChildHtml(‘‘); //加载所有的子block
  3. getChildChildHtml (‘container1‘ ,  ‘b‘ ,  true ,  true); //加载子block container1以及他的子block(as=‘b‘);
  4. getChildChildHtml (‘container1‘ ,  ‘‘ ,  true ,  true);  //加载子block container1,以及下面的所有子block
    1. <?php  echo  $this -> getChildChildHtml ( ‘container1‘ ,  ‘‘ ,  true ,  true )  ?>
    2. <?php  echo  $this -> getChildChildHtml ( ‘container2‘ ,  ‘‘ ,  true ,  true )  ?>
  5. Magento默认的配置下,HTML输出是从名为“root”的块开始(其实是因为这个块 拥有output属性【EFISH注:任何一个拥有output属性的块都是顶层块,在拥有多个顶层块的情况下Magento将按照块定义的先后顺序输出 HTML】)。我们覆盖了“root”块的模板

    template="../../../../../code/local/Alanstormdotcom/Helloworld/simple_page.phtml"
    模板文件的查找路径是当前主题(theme)的根目录,Magento默认设置时这里
    app/design/frontend/base/default

    为页面加入内容

    到目前为止,我们的页面都比较无聊,啥也没有。我们来为页面加点有意义的内容。修改 local.xml如下
    <helloworld_index_index>
    <reference name="root">
    <block type="page/html" name="root" template="../../../../../code/local/Alanstormdotcom/Helloworld/simple_page.phtml">
    <block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml"/>
    </block>
    </reference>
    </helloworld_index_index>

    我们在“root”块里面嵌套了一个块“customer_form_register”。这个块是Magento本来就有的,包含了一张用户注册表单。 我们把这个块嵌套进来,那么我们在模板文件里面就能用这个块的内容。使用方法如下,修改simple_page.phtml
    <body>
    <?PHP echo $this->getChildHtml(‘customer_form_register‘); ?>
    </body>

    这里“getChildHtml”的参数就是要引入的块的名字,使用起来相当方便。清空Magento缓存,刷新hello world页面,你应该在红色背景上看到用户注册表单。Magento还有一个块,叫做“top.links”,让我们把它也加进来。修改 simple_page.html
    <body>
    <h1>Links</h1>
    <?php echo $this->getChildHtml(‘top.links‘); ?>
    <?php echo $this->getChildHtml(‘customer_form_register‘); ?>
    </body>

    刷新页面,你会发现<h1>Links</h1>显示出来了,但是“top.links”什么都没有显示。那是因为我们并没有把 这个块引入到local.xml,所以Magento找不到这个块。“getChildHtml”的参数一定要是当前页面的布局文件中声明过的块。这样的 话Magento就可以只实例化需要用到的块,节省了资源,我们也可以根据需要为块设置不同的模板文件。

    我们修改local.xml文件如下
    <helloworld_index_index>
    <reference name="root">
    <block type="page/html" name="root" template="../../../../../code/local/Alanstormdotcom/Helloworld/simple_page.phtml">
    <block type="page/template_links" name="top.links"/>
    <block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml"/>
    </block>
    </reference>
    </helloworld_index_index>

    清空Magento缓存,刷新页面,你会看到一排链接显示出来了。【EFISH注:如果你细心一点的话你会发现“top.links”块没有template属 性,那是因为这个块的类中一定定义了默认的模板
    protected function _construct()
    {
    $this->setTemplate(‘page/template/links.phtml‘);
    }

时间: 2024-08-09 15:57:57

magento函数getChildHtml() 与getChildChildHtml() 的用法的相关文章

二.jQuery源码解析之构建jQuery之构建函数jQuery的7种用法

一:$(selectorStr[,限制范围]),接受一个选择器(符合jQuery规范的字符串),返回一个jQuery对象;二:$(htmlStr[,文档对象]),$(html[,json对象])传入html字符串,创建一个新的dom元素 三:$(dom元素),$(dom元素集合)将dom元素转换成jQuery对象.四:$(自定义对象)封装普通对象为jQuery对象.五:$(回调函数)绑定ready事件监听函数,当Dom加载完成时执行.六:$(jQuery对象)接受一个jQuery对象,返回一个j

MATLAB 函数句柄Function handle的用法(Af = @(x) A*x;)

函数句柄的作用是可以把函数句柄直接设置为参数然后执行 函数句柄(Function handle)是MATLAB的一种数据类型.引入函数句柄是为了使feval及借助于它的泛函指令工作更可靠:使“函数调用”像“变量调用”一样方便灵活:提高函数调用速度,特别在反复调用情况下更显效率:提高软件重用性,扩大子函数和私用函数的可调用范围:迅速获得同名重载函数的位置.类型信息. MATLAB中函数句柄的使用使得函数也可以成为输入变量,并且能很方便的调用,提高函数的可用性和独立性. 例如: 新建M文件f1.m

C++中的默认函数与default和delete用法

时间:2014.05.08 地点:基地 -------------------------------------------------------------------------------- 一.类中的默认函数 a.类中默认的成员函数 1.默认构造函数 2.默认析构函数 3.拷贝构造函数 4.拷贝赋值函数 5.移动构造函数 6.移动拷贝函数 b.类中自定义的操作符函数 1.operator 2.operator& 3.operator&& 4.operator* 5.op

数据仓库之抽取数据:openrowset函数带bulk操作符的用法

原文:数据仓库之抽取数据:openrowset函数带bulk操作符的用法 在做数据仓库时,最重要的就是ETL的开发,而在ETL开发中的第一步,就是要从原OLTP系统中抽取数据到过渡区中,再对这个过渡区中的数据进行转换,最后把经过处理的干净的数据加载到数据仓库中. 目标数据库是sql server,通过openrowset函数带bulk操作符的用法,导入.导出.更新数据. 带bulk操作符的方式相对于其他方式来说,速度更快. 使用方法: 第1种用法: openrowset ( bulk 要加载结果

Oracle中的填充函数lpad和rpad的用法(转)

原文链接:http://blog.csdn.net/myzhanglt/article/details/7392999 今日学习遇到一个不熟悉的函数LPAD,查了一下文档,将其用法总结如下: Lpad Function:在PL/SQL中用于往源字符串的左侧填充一些字符. 函数参数:lpad( string1, padded_length, [ pad_string ] ) 其中 string1:源字符串 padded_length:最终返回的字符串的长度,如果最终返回的字符串的长度比源字符串的小

Python 内置函数sorted()有哪些高级用法?

本文和大家分享的主要是python内置函数sorted()的相关内容,一起来看看吧,希望对大家学习python http://www.maiziedu.com/land/python/有所帮助. 1.对于 Python 内置函数 sorted() ,先拿来跟list(列表)中的成员函数 list.sort() 进行下对比.在本质上,list的排序和内建函数sorted的排序是差不多的,连参数都基本上是一样的. 2.主要的区别在于, list.sort() 是对已经存在的列表进行操作,进而可以改变

为什么需要main函数,及其参数的用法

首先,需要明确main函数是什么? 答:main函数是C语言约定的入口函数 C99标准里面是这样描述的: Program startup The function called at program startup is named main.The implementation declares no prototype for this function. It shall be de?ned with a return type of int and with no parameters:

sstream头文件-getline 函数 和 stringstream函数 和string的常见用法

#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string line; while(getline(cin,line) { int sum = 0, x; stringstream ss(line); while(ss>>x) { sum += x; } cout << sum << endl; }

(C++)STL排序函数sort和qsort的用法与区别

主要内容: 1.qsort的用法 2.sort的用法 3.qsort和sort的区别 qsort的用法: 原 型: void qsort(void *base, int nelem, int width, int (*fcmp)(const void *,const void *)); 功 能: 使用快速排序例程进行排序 参 数: 1 待排序数组首地址 2 数组中待排序元素数量 3 各元素的占用空间大小 4 指向函数的指针,用于确定排序的顺序 说 明:qsort函数是ANSI C标准中提供的,其