`
天梯梦
  • 浏览: 13763584 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

magento 创建block create structural blocks

 
阅读更多

Step 1: Name the structural block

Open the file layout/page.xml in your active theme folder. Inside you will find lines like:

<block type="core/text_list" name="left" as="left"/>
<block type="core/text_list" name="content" as="content"/>
<block type="core/text_list" name="right" as="right"/>
 

Let’s mimic this and add a new line somewhere inside the same block tag.

 <block type="core/text_list" name="myblock" as="myblock"/> 
  

Good. Now we told Magento that new structural block exists with the name “newreference”. Magento still doesn’t know what to do with it.

Step 2: Tell Magento where to place it

We now need to point Magento where it should output this new structural block. Let’s go to template/page folder in our active theme folder. You will notice different layouts there. Let’s assume we want the new structural block to appear only on pages that use 2-column layout with right sidebar. In that case we should open 2columns-right.phtml file.

Let’s assume we wish the “newreference” block to be placed below 2 columns, but above the footer. In this case, our updated file could look like this:

 <div id="myblock"><?php echo $this->getChildHtml('myblock') ?></div> 
  

Step 3: Populating structural block

We have the block properly placed, but unfortunately nothing is new on the frontsite. Let’s populate the new block with something. We will put new products block there as an example. Go to appropriate layout XML file and add this block to appropriate place.

 <reference name="myblock">
     <block type="core/template" name="myblock.search" as="myblockSearch" template="catalogsearch/myblock.search.phtml"/>
</reference> 
 

That’s it. I hope it will help someone :)

 

 

 

 

 

分享到:
评论

相关推荐

    magento中block应用

    在Magento中,Block实例由布局XML文件定义,通过`&lt;block&gt;`标签创建,并指定其类型、名称和其他属性。然后,Magento会根据这些定义来实例化Block对象,执行构造函数和`_construct`方法,加载数据,最后调用`toHtml`...

    magento创建动态菜单 Create Dynamic CMS Navigation For Magento Frontend

    在这个主题中,“Create Dynamic CMS Navigation For Magento Frontend”指的是在Magento的前端生成可以根据CMS页面自动生成的动态菜单。 在Magento中,静态菜单通常是通过后台管理界面手动创建和维护的,而动态...

    magento static block

    Block items can include any content that Magento CMS can involve Powerful block view scheduler Per-category and per-store view aheadWorks Market Segmentation Suite extension integration Enabling/...

    Magento创建管理列表和后台模块实例

    如果你正在创建一个Magento的管理模块(学习创造Magento管理模块),那么你一定会被要求创建一个管理列表既Grid。创建列表,Magento新手程序员有点困难,但在本教程中,我们将创建一个网格在管理模块中最简单的方式...

    magento创建自定义页面 (Bestseller实例) Bestseller products in Magento

    8. **清理缓存**:完成上述步骤后,别忘了清理Magento的布局和Block缓存,以便系统能识别新的改动。 通过以上步骤,你将能够在Magento中成功创建一个显示Bestseller产品的自定义页面。这个过程涉及到了Magento的...

    如何创建magento模块

    ### 如何创建Magento模块 #### 一、理解Magento模块的概念 在Magento中,所有功能性的扩展都是通过模块来实现的。这些模块可以是官方提供的,也可以是第三方开发的,甚至是自己定制开发的。一个模块就是一个相对...

    Create new module “HelloWorld” – in Magento

    return $this-&gt;resultPageFactory-&gt;create()-&gt;setBlock($block)-&gt;renderView(); } } ``` 3. **View**: 视图负责展示内容。在`View`目录下创建`frontend`子目录,然后创建`templates`子目录。在这里,创建一个名为...

    Magento系统请求响应流程图

    Block 使用 Helpers,这一步骤中,Blocks 使用 Helpers 来处理一些特定的功能,Helpers 是 Magento 的一个组件,负责处理一些辅助功能。 步骤 14:Helpers 使用 Object Models 资源 Helpers 使用 Object Models ...

    magento入门文档

    CRUD是指Create(创建)、Read(读取)、Update(更新)、Delete(删除),这是模型中最常见的操作。 **4.10 模型集合** 模型集合是一组模型的集合,可以用于处理多个模型对象的操作。 **4.11 总结** 通过使用...

    Magento深入理解Magento

    为了更直观地了解Magento配置系统的工作原理,本节将介绍如何创建一个简单的Magento模块,并分析其背后的配置机制。 1. **设置模块目录结构** Magento的模块结构通常遵循一定的规范。例如,官方提供的模块位于`...

    Magento 添加后台管理 addColumn

    你需要创建一个新的Block类,继承自Magento的AbstractBlock类,并实现数据获取的方法。 4. **修改Grid Block**: - 在Magento后台,数据通常以Grid形式展示。找到对应的Grid Block,例如`Mage_Adminhtml_Block_...

    Magento 1.4.2 简便生成订单函数

    通过上述介绍可以看出,`generateQuote`函数提供了一种简便的方式,使得开发者能够在Magento 1.4.2环境中快速生成订单引用对象,从而大大简化了订单创建的过程。这对于熟悉Magento框架的人来说是非常有用的工具,...

    Magento在代码中调用CMS静态块 (Static Block)

    这段代码的核心是`createBlock`方法,它用于创建一个指定类型的布局块,此处类型为`cms/block`,表示我们想要创建的是一个CMS静态块对象。接下来的`setBlockId`方法则用于设置要加载的静态块的ID,本例中为`...

    Magento模块开发教程.pdf

    创建好这两个文件以后,Magento 就知道你的模块存在,但是现在你的模块不会做任何事情。 在 Magento 中,模块是核心组件,Magento 的所有功能都是基于模块的。Magento 的系统模块就在 app/code/core/Mage 目录下面...

    Magento 后台管理插件示例

    在这个“Magento后台管理插件示例”中,我们将深入探讨如何利用Magento的架构来创建自定义管理插件,特别是关注USDP(假设是Unique Solution for Development Practice,一个用于命令空间的标识)的概念。...

    magento学习重点

    Magento的模板文件调用是通过Block对象实现的。Block对象是页面构建的基本单元,它们负责渲染HTML和执行业务逻辑。例如,`header` Block在`page.xml`布局文件中被定义,然后在页面模板文件(如`1column.phtml`)中...

    Magento插件开发手册 Magento Extension Developers Guide

    《Magento插件开发手册》是一份详尽的指南,旨在帮助开发者理解Magento的核心架构、编码标准以及如何创建和部署自定义插件。 ### Magento核心架构与代码组织 Magento的核心应用结构基于模块化设计,允许开发者通过...

    magento 中文开发手册

    3. **布局、块和模板**:讲解了 Magento 的页面布局机制,包括布局更新 XML 文件、Block 类和模板文件的使用。 4. **模型和 ORM 基础**:介绍了 Magento 如何使用 Entity-Attribute-Value (EAV) 模型存储数据,并...

    magento2 developers cookbook

    书中指导开发者如何创建一个带有样本数据的Magento 1网站,准备从Magento 1升级的过程,创建Magento 2网站以及如何升级数据库。这些步骤对于保持数据完整性和用户体验的连贯性至关重要。 在处理产品时,开发者可以...

    magento二次开发大全

    Magento是一款强大的开源电子商务平台,以其高度可定制性和灵活性著称。在进行Magento的二次开发时,你需要理解并掌握以下几个核心概念和技术: 1. **MVC架构**:Magento基于Model-View-Controller(MVC)设计模式...

Global site tag (gtag.js) - Google Analytics