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

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

问题描述

我正在尝试重新组织我的右侧边栏.在模板(2columns-right)中,它调用:

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

getChildHtml('right') ?>

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

Where can I find the content of this variable?

推荐答案

A call to method getChildHtml() 加载子块的 HTML 和传递给方法的名称,所以在在这种情况下,我们正在寻找一个名为 right 的子块.

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.

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

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>

在布局文件中使用 标签允许您更改目标块,而 标签允许您运行块方法在您正在使用的块内.所以这部分布局在 root 块内设置模板.由此我们知道它是调用 getChildHtml() 方法的 root 块.

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.

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

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>

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

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.

如您所见,此处定义了 right 块,但它是空的.这是因为与您的标签引用根块(<reference name="root">)的方式完全相同,其他布局文件将子块添加到右侧 通过引用 right 块来阻止.

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>

因此,为了最终回答您的问题(并希望在此过程中提供一些信息),您需要查看 page.xml 以外的布局文件以获取对 right 块,在这里您将找到 getChildHtml() 方法调用输出的所有子内容.

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.

您可以在自己的模块布局文件或 local.xml 布局文件中更改添加到 right 块的内容,如果您不创建模块.我在回答 此处 使用示例语法添加新块和删除其他布局文件中添加的块.

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天全站免登陆