【9】了解淘宝sdk引入布局模块

上一节我们说了下淘宝提供给我们可布局的地方;

这一节我们说下淘宝sdk布局模块。

在我们开发网店的时候一般一个网店组成是:页面>框架>模块(>的意思的包含);这样我们就知道我们一般开发都集中在模块的开发和美化,特别是你买过淘宝上的板子,你就会发现,有的设计师会时不时的更新升级下模块,要不就是开发新模块出来。

所以我们开发网店也要学习下怎么开发模块,但是前提的你要先学会引用模块,一般引用有2种:

【1】引用系统模块-----方法如下:

1 <?php
2 
3     echo  include_system_module("shop.picRound","1.0-common",100); //这个是系统轮播模块
4 
5 ?>

参数说明:include_system_module需要三个参数,第一个为“系统模块简称”,第二个为“系统模块版本”,第三个为domId,这里需要注意的是domId需要在页面内唯一(和div中的id是一样的,一个页面中只能出现一次)

 

【2】引用自定义模块-----方法如下:

1 <?php
2            
3         echo  include_local_module("textbox",101);
4 
5 ?>

参数说明:include_local_module有两个参数,第一个”textbox”为模块的名称,第二个为domId,这里需要注意的是domId需要在页面内唯一。

 

学会了引用模块,那我们在学一个东西-----引入片区

那有人会问什么的片区???

片区是设计师在页面预留的一块区域,卖家可以在坑里添加模块,具体引入坑的语法如下:

<div id=" navigator"  class=" J_TRegion">

    <?php

     	$topList=array('shortname'=>'shop.topList','version'=>'1.0-common',domId=>001);

        $selfModule=array('id'=>'selfModule','domId'=>'001');

        $modules=array($topList, $selfModule);

               echo include_modules("testModules", $modules)

               echo include_system_module("shop.searchInShop","1.0-common",002)

   ?>

</div>

 参数说明:include_modules包含两个参数,第一个参数是片区对应的名称,第二个参数是片区里面引入的默认模块列表。

引入片区需要注意以下几点:

 1. 片区需要通过“J_TRegion”这个class来标识.

2. 片区里面也可以引入系统模块和引入自定义模块

好了,引用片区我们也学了,但是这里我也有些没有看懂

【1】“J_TRegion”外模块引用规范

【2】“J_Region内模块的引用支持单个模块和多个模块

这里的说明看的我糊涂了,要是有懂的,可以说说,有兴趣的也可以自己看看,网址:http://wiki.zx.taobao.com/index.php/模板编写规范

 

我们说也说了这么多,那我们就开始小小实战一下,在index.php页引用一下系统的轮播器(shop.picRound)用用,代码如下

<div class="layout grid-m">
     <div class="J_TRegion">
	     <?php
		     echo include_system_module("shop.picRound","1.0-common",001) 
	     ?>
     </div>
</div>

 这里有个重点就是申明片区要通过“J_TRegion”这个class来标识.,这个在上面我也讲到了,其他的也说到了,大家注意自己分析下。

写好了后,在控制台上找到自己新建的模板中的首页(index)预览下看看,是不是已经有一个轮播了。

 

模板中加入模块配置

设计师经常会遇到这样的问题:在模板挖了坑,但是没有办法控制坑中能够添加哪些模块。现在在SDK模板中加入了新的配置规则,允许设计师精确配置自己坑中所支持的模块。

示例配置如下:

View Code
 1 <?xml version="1.0" encoding="GBK"?>
 2 <site version="1">
 3     <id>9bb679384bb64c59be4f23ca37b6bcf7</id>
 4     <name>xiaohu</name>
 5     <author wangwang="" url="http://www.taobao.com"></author>
 6     <thumbnail>assets/images/frontpage.png</thumbnail>
 7     <language>php</language>
 8     <version>1.0.0</version>
 9     <apply-sites>3,7</apply-sites>
10     <change-notes>
11         change log
12     </change-notes>
13     <description>
14         description
15     </description>
16     <parameters>
17         <param name="demo" description="只读属性-1" readonly="true" ptype="text" formType="text" label="label">demo</param>
18         <param name="theme" description="主题风格" ptype="text" formType="text" label="label">green</param>
19     </parameters>
20     <global>
21         <header>header.php</header>
22         <footer>footer.php</footer>
23         <css>assets/stylesheets/global.css</css>
24     </global>
25     <styles default="gray">
26         <style>
27             <name>gray</name>
28             <thumbnail>/assets/images/frontpage.png</thumbnail>
29             <css>assets/stylesheets/gray.css</css>
30         </style>
31     </styles>
32     <rules>
33             <common>
34                 <support>
35                    <module shortname="shop.searchInShop" version="1.0-common"/>
36                    <module shortname="shop.topList" version="1.0-common"/>
37                    <module shortname="shop.friendLink" version="1.0-common"/>
38                 </support>
39             </common>
40 
41 
42             <header>
43                 <placeholder name="head-modules">
44                     <support>
45                         <module shortname="shop.itemCategory" version="1.0-common"/>
46                     </support>
47                 </placeholder>
48             </header>
49 
50 
51             <footer>
52                  <placeholder name="foot-modules">
53                     <support>
54                         <module shortname="shop.fileList" version="1.0-common"/>
55                         <module id="side_sales"/>
56                     </support>
57                 </placeholder>
58             </footer>
59     </rules>
60     <pages>
61         <page type="index">
62             <name>首页</name>
63             <file>index.php</file>
64             <thumbnail>assets/images/index.png</thumbnail>
65             <description>sjgjweogj</description>
66             <rules>
67                 <placeholder name="sub-modules">
68                     <support>
69                         <module shortname="shop.itemCategory" version="1.0-common"/>
70                         <module shortname="shop.fileList" version="1.0-common"/>
71                         <module id="side_help"/>
72                         <module id="side_sales"/>
73                     </support>
74                 </placeholder>
75             </rules>
76         </page>
77     </pages>
78 </site>

在site节点下的rules中配置通用的模块和头部尾部模块,

在page节点下的rules中配置具体页面下坑中支持的模块。

通用模块的配置不需要指定坑的名称,头,尾,页面中的模块配置需要指定到页面中的具体的坑名。

具体坑中支持哪些模块的计算方式是,通用配置集合与当前坑模块集合的并集。

模块配置支持系统模块和设计师自定义的模块两种模块类类型。

 

posted @ 2012-04-23 14:55  huige728  阅读(1966)  评论(6编辑  收藏  举报