昨天下午接到需求说要增加一个新的页面,作为优惠活动规则的介绍之用,之前对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. 自定义progressbar

    <ProgressBar android:id="@+id/progressBar1" android:layout_width="wrap_content&quo ...

  2. POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)

    题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...

  3. noip2000提高组题解

    事实再次向我证明了RP的重要性... 第一题:进制转换 是我最没有把握AC的一道题目却是我唯一一道AC的题目,真是讽刺.看完题目几乎完全没有往正常的解法(取余倒序)去想,直接写了搜索,因为数据范围在2 ...

  4. test chemes

    rcmobile://messages rcmobile://badge rcmobile://dialer rcmobile://open rcmobile://sms?type=new

  5. TCP/IP详解学习笔记(1)-基本概念

    为什么会有TCP/IP协议 在世界上各地,各种各样的电脑运行着各自不同的操作系统为大家服务,这些电脑在表达同一种信息的时候所使用的方法是千差万别.就好像圣经中上帝打乱了各地人的口音,让他们无法合作一样 ...

  6. 给IT新男的15点建议:苦逼程序员的辛酸反省与总结

    很多人表面上看着老实巴交的,实际上内心比谁都好强.自负.虚荣.甚至阴险.工作中见的多了,也就习惯了. 有一些人,什么事都写在脸上,表面上经常得罪人,甚至让人讨厌.但是他们所表现的又未必不是真性情. 我 ...

  7. SQL SERVER 实现分组合并实现列数据拼接

    需求场景: SQL SERVER 中组织的数据结构是一个层级关系,现在需要抓出每个组织节点以上的全部组织信息,数据示例如下: ADOrg_ID--------------ParentID------- ...

  8. 【LeetCode 173】Binary Search Tree Iterator

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...

  9. 【LeetCode 209】Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  10. Windows套接字Socket函数

    1.使用套接字函数之前,先要加载套接字函数库: #include "Winsock2.h" #pragma comment(lib,"Ws2_32.lib") ...