Smarty

一、smarty在某一tpl中能夠在任何地方定義變量,任何地方賦值,而後全局生效,例如:在公共頭作判判定義變量,在版塊模板頁賦不一樣的值。javascript

公共頭頁面head.tpl:
{if $ishavenav}
    <div class="head-icon">
        <a class="icon-nav" id="wap{$controlName}xx_xxx" href="javascript:void(0);">
                <span class="sms-num" style="display:none;"></span><span ><i></i><p>導航</p></span>
        </a>
    </div>
{/if}

某一用到head.tpl的模板頁:
{include file="public/inc.header_inside.html"
  title="個人XX"
  headTitle="個人瀏覽-XXXX網"
  ishavenav=true
}
這樣就能夠起到進入公共頭判斷的做用。

二、smarty中fetch和display的區別
 在Smarty模板函數裏面有這樣一個方法:fetch("template.htm"),他和display("template.htm");最大的不一樣就是fetch()是把內容輸出給一個變量,而display()是把內容輸出給瀏覽器,這樣咱們就能夠用一個變量來接收fetch()的輸出,而後把他寫入到文件中去.
self::$_smarty->assign('result', $result['node']);
$jsondata=self::$_smarty->fetch("tudi/ajaxGetTudi.html");

三、smarty函數count_characters[字符計數]php

例如:顯示10行,控制字數

{if $result.SNote|strip_tags|strip|count_characters > 858}
相關文章
相關標籤/搜索