昨天下午接到需求说要增加一个新的页面,作为优惠活动规则的介绍之用,之前对ecshop各种修改,但是这次自己做页面还是第一次,文件太多,函数也太多,一个一个的读过来时间很头疼的事情,于是就参照goods.dwt和goods.dwt来做页面,由于该页面仅仅是一个优惠活动规则的介绍,所以静态的页面就可以搞定。由于顶部、尾部、还有一个左边的分类树和浏览记录是需要,所以需要在dwt文件中引入page_header.lbi、page_footer.lbi、category_tree.lbi、以及history.lbi四个库文件。

下面我们来一一说明

一、引入lbi库原理

因为ecshop使用的是smarty引擎,实现了php代码和html代码(dwt文件)的分离,所以在dwt文件中引用的ecshop变量{$xx}以及引入lbi文件中的{$xx}都必须事先在对应的php中assign,比如a.dwt中的ecshop变量需要现在a.php中assign

二、详细

2.1、page_header.lbi和page_footer.lbi的引入

引入代码:

<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->

<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->

查看其中任意一个的代码,以page_header.lbi为例:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var process_request = "{$lang.process_request}";
</script>
<div class="block clearfix">
 <div class="f_l"><a href="../index.php" name="top"><img src="../images/logo.gif" /></a></div>
 <div class="f_r log">
   <ul>
   <li class="userInfo">
   {insert_scripts files='transport.js,utils.js'}
   <font id="ECS_MEMBERZONE">{* ECSHOP 提醒您:根据用户id来调用member_info.lbi显示不同的界面  *}{insert name='member_info'} </font>
   </li>
   <!--{if $navigator_list.top}-->
   <li id="topNav" class="clearfix">
    <!-- {foreach name=nav_top_list from=$navigator_list.top item=nav} -->
            <a href="{$nav.url}" <!-- {if $nav.opennew eq 1} --> target="_blank" <!-- {/if} -->>{$nav.name}</a>
            <!-- {if !$smarty.foreach.nav_top_list.last} -->
             |
            <!-- {/if} -->
    <!-- {/foreach} -->
    <div class="topNavR"></div>
   </li>
   <!-- {/if} -->
   </ul>
 </div>
</div>
<div  class="blank"></div>
<div id="mainNav" class="clearfix">
  <a href="../index.php"{if $navigator_list.config.index eq 1} class="cur"{/if}>{$lang.home}<span></span></a>
  <!-- {foreach name=nav_middle_list from=$navigator_list.middle item=nav} -->
  <a href="{$nav.url}" {if $nav.opennew eq 1}target="_blank" {/if} {if $nav.active eq 1} class="cur"{/if}>{$nav.name}<span></span></a>
 <!-- {/foreach} -->
</div>
<!--search start-->
<div id="search"  class="clearfix">
  <div class="keys f_l">
   <script type="text/javascript">
    {literal}
    <!--
    function checkSearchForm()
    {
        if(document.getElementById('keyword').value)
        {
            return true;
        }
        else
        {
            alert("{$lang.no_keywords}");
            return false;
        }
    }
    -->
    {/literal}
    </script>
    {if $searchkeywords}
   {$lang.hot_search} :
   {foreach from=$searchkeywords item=val}
   <a href="search.php?keywords={$val|escape:url}">{$val}</a>
   {/foreach}
   {/if}
  </div>
  <form id="searchForm" name="searchForm" method="get" action="search.php" onSubmit="return checkSearchForm()" class="f_r"  style="_position:relative; top:5px;">
   <select name="category" id="category" class="B_input">
      <option value="0">{$lang.all_category}</option>
      {$category_list}
    </select>
   <input name="keywords" type="text" id="keyword" value="{$search_keywords|escape}" class="B_input" style="width:110px;"/>
   <input name="imageField" type="submit" value="" class="go" style="cursor:pointer;" />
   <a href="search.php?act=advanced_search">{$lang.advanced_search}</a>
   </form>
</div>
<!--search end-->

通过看代码我们会发现navigator_list这个变量(下划线标注部分),但是通过搜索good.php文件,并没有发现有这个变量被assign,那么他来自哪里呢?

经过仔细研究发现这个navigator_list变量是在includes/lib_main.php中的assign_template函数中被assign,而在goods.php中引用了这个方法,那么到此为止,这个问题得到解决,我们需要在a.php中也调用这个函数。

2.2、category_tree.lbi的引入

引入代码:

<!-- #BeginLibraryItem "/library/category_tree.lbi" --><!-- #EndLibraryItem -->

查看category_tree.lbi的代码:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="box">
 <div class="box_1">
  <div id="category_tree">
    <!--{foreach from=$categories item=cat}-->
     <dl>
     <dt><a href="{$cat.url}">{$cat.name|escape:html}</a></dt>
     <!--{foreach from=$cat.cat_id item=child}-->
     <dd><a href="{$child.url}">{$child.name|escape:html}</a></dd>
       <!--{foreach from=$child.cat_id item=childer}-->
       <dd>&nbsp;&nbsp;<a href="{$childer.url}">{$childer.name|escape:html}</a></dd>
       <!--{/foreach}-->
     <!--{/foreach}-->

       </dl>
    <!--{/foreach}-->
  </div>
 </div>
</div>
<div class="blank5"></div>

我们看到红色下划线部分变量是通过调用includes/lib_goods.php的get_categories_tree函数进行引入

2.3、history.lbi的引入

引入代码:

<!-- #BeginLibraryItem "/library/history.lbi" --><!-- #EndLibraryItem -->

查看history.lbi代码:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="box" id='history_div'>
 <div class="box_1">
  <h3><span>{$lang.view_history}</span></h3>
  <div class="boxCenterList clearfix" id='history_list'>
    {insert name='history'}
  </div>
 </div>
</div>
<div class="blank5"></div>
<script type="text/javascript">
if (document.getElementById('history_list').innerHTML.replace(/\s/g,'').length<1)
{
    document.getElementById('history_div').style.display='none';
}
else
{
    document.getElementById('history_div').style.display='block';
}
function clear_history()
{
Ajax.call('user.php', 'act=clear_history',clear_history_Response, 'GET', 'TEXT',1,1);
}
function clear_history_Response(res)
{
document.getElementById('history_list').innerHTML = '{$lang.no_history}';
}
</script>

我们发现红色下划线部分的代码,其调用的是includes/lib_insert.php中的insert_history函数。不用我们再进行assign。

在自定义的dwt文件中调用page_header.lbi和page_footer.lbi的更多相关文章

  1. JavaScript文件中调用AngularJS内部方法或改变$scope变量

    需要在其他JavaScript文件中调用AngularJS内部方法或改变$scope变量,同时还要保持双向数据绑定: 首先获取AngularJS application: 方法一:通过controll ...

  2. [Xcode 实际操作]九、实用进阶-(6)在Swift文件中调用Object-C的类和方法

    目录:[Swift]Xcode实际操作 本文将演示在Swift文件中调用Object-C的类和方法. 在项目文件夹[DemoApp]上点击鼠标右键 ->[New File]创建一个Object- ...

  3. Springboot读取自定义的yml文件中的List对象

    Yml文件(novellist.xml)如下: novellist:   list:     - name: 笑傲江湖       type: 武侠       master: 令狐冲       a ...

  4. 微信小程序wxml文件中调用自定义函数

    想在微信小程序的wxml文件里自如的像vue那样调用自定义的方法,发现并不成功,得利用WXS脚本语言. WXS脚本语言是 WeiXin Script 脚本语言的简称,是JavaScript.JSON. ...

  5. [置顶] lua 进阶3--lua文件中调用C++函数

    前面讲了一下,C++读取lua文件中的变量,包括一维表.二维表这些,这节讲一下如何在lua文件中去调用C++函数 C++代码如下 #include <stdio.h> extern &qu ...

  6. CUDA常见问题之无法在c文件中调用cu文件中定义的函数

    当在C源文件中调用cu文件中定义的函数时,会出现undefined reference的问题,而在C++源文件中调用cu文件中定义的函数时则不会出现这个问题. 出现上述问题的原因是,nvcc编译器采用 ...

  7. Js文件中调用其它Js函数的方法

    在项目开发过程中,也许你会遇这样的情况.在某一Js文件中需要完成某一功能,但这一功能的大部分代码在另外一个Js文件中已经完成了,自己只需要调用这个方法再加上几句代码就可以实现所需的功能.我们知道,在h ...

  8. sql自定义函数及C#中调用

    1.在C#中调用sql自定义函数 1.1 标量值函数 sql语句调用 select  dbo.GetClassIDWithName(1) string strSql = string.Format(& ...

  9. C++学习——在C文件中调用C++文件中的函数

    1.CPP文件中的内容 #include "mytest.h" #include <iostream> using namespace std; int add(con ...

随机推荐

  1. vs2010 js代码折叠

    方法一:插件   在Visaul Studio 2010中写js或css代码,缺少像写C#代码时的那种折叠功能,当代码比较多时,就很不方便. 但是已经有VS2010扩展支持这个功能,它就是--JSEn ...

  2. Java Web编程的主要组件技术——Struts入门

    参考书籍:<J2EE开源编程精要15讲> Struts是一个开源的Java Web框架,很好地实现了MVC设计模式.通过一个配置文件,把各个层面的应用组件联系起来,使组件在程序层面联系较少 ...

  3. c++ 完成端口资料

    文章地址: http://blog.csdn.net/piggyxp/article/details/6922277 附件如下: word文档 PiggyIOCPServer_2008.rar Pig ...

  4. linux 定时任务调度Cron的用法详解

    在linux中,推荐使用crontab -e命令添加自定义的任务,退出后重启crond进程. 重新启动cron服务或重新加载cron配置,命令: 复制代码代码示例: /etc/rc.d/init.d/ ...

  5. 【转】ios app 应用内购买配置完全指南

    转自:http://blog.sina.com.cn/s/blog_4b55f6860100sbfb.html 第一印象觉得In-App Purchase(简称IAP)非常简单.Apple提供的大量文 ...

  6. delphi 对话框初始地址InitialDir

    我的电脑:SaveDialog1.InitialDir := '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';// My Computer {20D04FE0-3 ...

  7. 多线程监控文件夹,FlieSystemWatcher,并使用共享函数

    发表于: 2011-01-06 09:55:47   C# code   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ...

  8. [FIX BUG]获取theme中自定义textColor时报的错误

    我在Fragment中inflate它都可以,可是一旦使用ListView来inflate就会报错,说找不到我自定义的attr!研究了半天发现是我的inflate的context有问题: view = ...

  9. java web 学习十(HttpServletRequest对象1)

    一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...

  10. Storm的本地运行模式示例

    以word count为例,本地化运行模式(不需要安装zookeeper.storm集群),maven工程, pom.xml文件如下: <project xmlns="http://m ...