在哪里是<?php echo $ this-> getChildHtml('right')?> [英] Where is the content of <?php echo $this->getChildHtml(’right’) ?>

查看:206
本文介绍了在哪里是<?php echo $ this-> getChildHtml('right')?>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新整理我的右侧边栏。在模板(2列 - 右)中,它调用:



<?php echo $ this-> getChildHtml >



在哪里可以找到此变量的内容?

解决方案

调用方法 getChildHtml()子块与传递给方法的名称,因此在这种情况下,我们正在寻找一个名为 right 的子块。



在哪里找到这个子块我们需要知道哪个块调用这个方法。我知道特定调用 getChildHtml()方法出现在主页列模板中,因为 right 是其中一个列。因此,请查看 page.xml 布局文件,并搜索您在其中找到方法调用的模板文件,您会发现这样的:

 < reference name =root> 
< action method =setTemplate>< template> page / 2columns-right.phtml< / template>< / action&
<! - 标记根模板所在的页面块 - >
< action method =setIsHandle>< applied> 1< / apply>< / action&
< / reference>

使用< reference> 布局文件允许您更改目标块,< action> 标签允许您在正在使用的块中运行块方法。因此,这部分布局将模板设置在 root 块中。从这里我们知道是阻塞调用 getChildHtml()方法。



接下来让我们来看看在布局中定义的块的位置,它在同一个 page.xml 布局文件中,靠近顶部:

 < block type =page / htmlname =rootoutput =toHtmltemplate = page / 3columns.phtml> 
...
< block type =core / text_listname =rightas =righttranslate =label>
< label>右栏< / label>
< / block>
...
< / block>

在这个块中有很多定义,但是你可以看到, em> root 并定义了相当多的子块。这些子块之一被命名为 right ,并且它是由 getChildHtml()方法输出其HTML的块。注意块类型 - core / text_list 很重要。这是一个特殊的块类型,这意味着当使用 getChildHtml()方法渲染此块的HTML时,子块也将被渲染。如果块类型是 page / html 像根块,每个添加到块的子块需要它自己的 getChildHtml()方法调用,使用这个块类型,你只需要调用 getChildHtml('right')



正如你所看到的,右边的块在这里被定义,但它是空的。这是因为你的标签引用根块(< reference name =root> )的其他布局文件添加子块到

=right>
...
< / reference>

因此,为了最终回答你的问题在 page.xml 之外的布局文件中查找 right 块的引用,这里您将找到 getChildHtml()方法调用。



您可以更改添加到您自己的模块布局文件,或 local.xml 布局文件(如果不是创建模块)。我简要介绍了我的答案 local.xml to-header-not-display / 1500#1500>此处使用示例语法添加新块并删除在其他布局文件中添加的块。


I’m trying to re-organise my right sidebar. In the template (2columns-right), it calls :

<?php echo $this->getChildHtml('right') ?>

Where can I find the content of this variable?

解决方案

A call to method getChildHtml() loads the HTML for the child block with the name which is passed to the method, so in this case we are looking for a child block named right.

To determine where to find this child block we need to know which block is calling this method. I know that that particular call to the getChildHtml() method appears in the main page column template as right is one of the columns. So have a look in the page.xml layout file and search for the template file inside which you found the method call, you will find something like this:

<reference name="root">
    <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
    <!-- Mark root page block that template is applied -->
    <action method="setIsHandle"><applied>1</applied></action>
</reference>

Using the <reference> tag in a layout file allows you to alter the targeted block, and the <action> tag allows you to run a block method inside the block you are working with. So this section of layout sets the template inside the root block. From this we know that it is the root block calling the getChildHtml() method.

Next lets look at where the root block is defined in the layout, it's in the same page.xml layout file, and should be right near the top:

<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
    ...
    <block type="core/text_list" name="right" as="right" translate="label">
        <label>Right Column</label>
    </block>
    ...
</block>

There is quite a lot defined in this block, but you can see that it is given the name root and defines quite a few child blocks. One of these child blocks is named right and it is this block whose HTML is being output by the getChildHtml() method. It is important to note the block type - core/text_list. This is a special block type which means that when rendering out the HTML for this block using the getChildHtml() method, child blocks will also be rendered. If the block type was page/html like with the root block, every child block added to the right block would need it's own getChildHtml() method call, using this block type, you only need a call to getChildHtml('right') and all child blocks will also be rendered.

As you can see the right block is defined here but it is empty. This is because in exactly the same way as your have the tag referencing the root block (<reference name="root">) other layout files add child blocks to the right block by referencing the right block.

<reference name="right">
    ...
</reference>

So to finally answer your question (and hopefully inform a little along the way), you need to be looking in layout files other than page.xml for references to the right block, here you will find all of the child content output by the getChildHtml() method call.

You can alter what is added to the right block in your own module layout file, or local.xml layout file if you are not creating a module. I briefly cover the local.xml layout file in my answer here with example syntax to add new blocks and remove blocks added in other layout files.

这篇关于在哪里是&lt;?php echo $ this-&gt; getChildHtml('right')?&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆