帳號登錄
帳號:
密碼:
記住我 | 忘記密碼 | 帳號註冊
網站導覽
模組開發 : 建立一個簡單的模組:更好的樣板
作者 elie 於 2010年08月16日 22:06:52 (4366 次閱讀)

原始出處 http://www.xoops.org/modules/mediawiki/index.php/Making_a_simple_module:_An_active_template

 

上個範例中我們使用了一個很簡單的樣版,現在我將介紹實際設計中利用樣版引擎功能的樣版。

跟著下面的步驟使用樣版輸出表格:

1.建立templates 目錄,在目錄下新增"myTemplate.html" 且內容如下:

<table><tr><td colspan='2' align='center'>My Module Table</td></tr>  
                      
<{section name=i loop=$myArray step=1}>
        <{if $smarty.section.i.iteration % 2 == 0}>
               <td><{$myArray[i]}></td>
               </tr>
        <{else}>
               <tr>
               <td><{$myArray[i]}></td>
        <{/if}>
<{/section}>
               
</table>

2.編輯xoops_version.php 檔案新增:

    $modversion['templates'][1]['file'] = "myTemplate.html";
    $modversion['templates'][1]['description'] = "Our template file";

3.編輯index.php 使用樣版,並將結果輸出給樣版而不是使用echo 輸出到螢幕:

<?php //index.php
        require_once("../../mainfile.php");
        
        // this line must be defined BEFORE header.php
        $xoopsOption['template_main'] = "myTemplate.html";
        include XOOPS_ROOT_PATH."/header.php";
        //Our Example Array
        $myArray = array("Richard Nixon", "American Hero", "George W. Bush", "Vegetable", "Hoven Droven", "Swedish Folk Music done cool");
        $xoopsTpl->assign('myArray', $myArray);
        include XOOPS_ROOT_PATH."/footer.php";
?>

範例中可以看到我們的陣列指定給全域的Xoops 物件xoopsTpl 的smarty 樣版變數 'myArray'。


可列印模式 轉寄給朋友

The XOOPS organisation ("XOOPS") is committed to protecting the privacy of users of the XOOPS.org sites.
The website used Ver.2.4.5 POWERED BY XOOPS PROJECT.