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

查看:67
本文介绍了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并没有使用这些对象的类名,而是使用了类似URI的字符串,称为 class aliases .所以这个

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.

大多数块对象是模板块,即,Block类从基本的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

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.

如果您要进行自定义模块开发(而不是主题化),通常我会在自己的模块中创建一个Block Object来扩展基本的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天全站免登陆