Magento 主题中左列的块类型是什么? [英] What Block Type for Left Column in Magento Theme?

查看:19
本文介绍了Magento 主题中左列的块类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自定义 Magento (1.3) 主题,并且想要添加左列.

I'm working on a custom Magento (1.3) theme and am wanting to add a left column.

我已经用 html 创建了 template/page/html/left.phtml.

I've created template/page/html/left.phtml with the html in.

在 2columns-left.phtml 中,我添加了以下内容:

In 2columns-left.phtml, i've added the following:

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

在 page.xml 中,我添加了以下内容:

In page.xml, i've added the following:

<block type="page/html" name="left" as="left" template="page/html/left.phtml" />

我不太明白的是块类型应该是什么 - 如果我做 page/html、core/template 或 page/html_header 似乎可以工作 - 这是什么以及这种情况下的正确值是什么,我只想有效地包含一个 phtml 文件 - page/html/left.phtml 等

What i'm not quite understanding is what that block type should be - it seems to work if I do page/html, core/template or page/html_header - what is this for and what is the correct value for this case, where I just want to effectively include a phtml file - page/html/left.phtml etc.

谢谢,

伊恩

推荐答案

这是正在发生的事情的简化版本,但会希望足以让你前进.

This is a simplified version of what's going on, but will hopefully be enough to get you going.

Magento 认为有三种类型的对象是特殊的".它们是模型、块和助手.Magento 没有为这些对象使用类名,而是使用名为 class aliases 的类似 URI 的字符串.所以这个

There are three types of Objects that Magento considers "special". These are Models, Blocks, and Helpers. Rather than use class names for these objects Magento uses URI-like strings called class aliases . So this

page/html

对应于Block类

Mage_Page_Block_Html

这里的类指的是 PHP 类,而不是 CSS 类.

Class here is referring to PHP classes, not CSS classes.

布局对象负责为 Magento 页面创建所有 HTML.

A Layout Object is responsible for creating all the HTML for a Magento page.

布局对象是嵌套块对象的集合.

A Layout Object is a collection of nested Block Objects.

大多数块对象都是模板块,即块类继承自基础 Magento 模板块 Mage_Core_Block_Template.模板块是负责渲染 phtml 模板文件的对象.

Most Block Objects are Template Blocks, that is, the Block class inherits from the base Magento template block Mage_Core_Block_Template. Template Blocks are objects responsible for rendering a phtml template file.

因此,当您在 XML 布局文件中指定类型"时,您就是在告诉 Magento.

So, when you specify a "type" in the XML Layout files, you're telling Magento.

我想使用模板 baz.phtml 添加一个类为 foo/bar 的块对象

I want to add a block object with the class foo/bar, using the template baz.phtml

在代码中,就是

<!-- "name" and "as" are used to identify the block in the layout, so that 
PHP code can get a reference to the object. -->
<block type="foo/bar" name="myname" as="myname" template="path/to/baz.phtml" />

如果你只想渲染一个模板文件,你可以使用

If all you want to do is render a template file, you can use

type="core/template"

但是,通过使用不同的值,例如

However, by using a different value, like

type="page/html"

您的 phtml 模板文件可以访问

your phtml template file gets access to all the methods in

Mage_Page_Block_Html

这意味着你可以做类似的事情

Which means you could do something like

File: template.phtml

<a href="<?php echo $this->getBaseUrl();?>"></a>

core/template 类没有 getBaseUrl 方法,但 page/html 类有.

The core/template class doesn't have a getBaseUrl method, but the page/html class does.

如果您正在进行自定义模块开发(而不是主题化),我通常会在我自己的模块中创建一个块对象,以扩展基本 Magento 块之一.这允许我在我认为合适的时候将我自己的方法添加到块中.如果您只是主题化,page/html 是一个不错的默认设置.

If you're doing custom module development (as opposed to just theming), I usually create a Block Object in my own module that extends one of the base Magento blocks. This allows me to add my own methods to the block as I see fit. If you're only theming, page/html is a decent default.

这篇关于Magento 主题中左列的块类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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