QuickSkin简单学习--控制结构
QuickSkin簡單學習
3.控制結構
if
if ... endif 結構幫助模板的條件選擇。 QuickSkin支持和PHP相同的操作符. 比較操作符, 作為名稱暗示,允許你比較兩個值.
可以是以下的三種語法:
<!– IF var –> var is not empty! <!– ENDIF var –>
<!– IF name == ”John Doe” –> Your name is John Doe! <!– ENDIF name –>
<!– IF name != ”John Doe” –> Your name is not John Doe! <!– ENDIF name –>
變量也能用在語句中:
<!– IF name == variablename –> Your name match with {variablename} <!– ENDIF name –>
<!– IF name != top.variablename –> Your name doesn’t match with {top.variablename} <!– ENDIF name –>
(var after ENDIF is optional)
if.php:
模板: if.html:
<!-- IF username --> <H3> Welcome, {username} </H3> <!-- ENDIF --> ? ? <!-- IF picture --> <img src="{picture}"> <!-- ENDIF picture --> ? ? <!-- IF usergroup == "ADMIN" --> ? <a href="admin.php"> ADMIN Login </a> ? <!-- ENDIF usergroup --> ? <!-- BEGIN numbers --> <!-- IF value == parent.mynumber --> <b>{value}</b> <!-- ELSE --> {value} <!-- ENDIF value --> <!-- END numbers -->輸出結果:
<H3> Welcome, John Doe </H3> ? ? ? ? <a href="admin.php"> ADMIN Login </a> 0 1 2 3 <b>4</b> 5 6 7 8 9else
else結構擴展了if 結構來顯示模板的表達式為FALSE的情況。
else.php:
模板: else.html:
<!-- IF username --> ? <H3> Welcome, {username} </H3> ? <!-- ENDIF --> ? ? ? <!-- IF picture --> ? <img src="{picture}"> ? <!-- ELSE --> ? Picture not available! <br> ? <!-- ENDIF picture --> ? ? ? <!-- IF usergroup == "ADMIN" --> ? <a href="admin.php"> ADMIN Login </a><br> ? <!-- ELSE --> ? You are in guest mode! ? <!-- ENDIF usergroup -->輸出結果:
<H3> Welcome, John Doe </H3> ? ? ? ? ? Picture not available! <br> ? ? ? ? ? <a href="admin.php"> ADMIN Login </a><br>elseif
elseif結構是else和if 的結合體.
elseif.php:
模板:elseif.html:
<!-- IF usergroup == "ADMIN" --> ? <a href="admin.php"> Admin Staff Login </a><br> ? <!-- ELSEIF usergroup == "SUPPORT" --> ? <a href="support.php"> Support Staff Login </a><br> ? <!-- ELSEIF usergroup --> ? <a href="other.php"> Standard Login </a><br> ? <!-- ELSE --> ? You don't even have a usergroup! ? <!-- ENDIF -->輸出結果:
<a href="other.php"> Standard Login </a><br>begin endbegin end
begin ... end提供了一個數組的迭代方法.每一個數組期待這是一個關聯數組并用來分析模板的部分并用來替代模板的 <!– BEGIN –><!– END –> 標記
每個關聯數組擴展了一下兩個常量:
ROWCNT : 文本的實際數量. (0,1,2,3,...n)
ROWBIT : 不同的位的不用意義. (0,1,0,1,0,1,...)
begin_end.php:
<?php ? require_once "class.quickskin.php"; $page = new QuickSkin("begin_end.html"); ? $users = array( array( 'NAME' => 'John Doe', 'GROUP' => 'ADMIN' ), array( 'NAME' => 'Jack Doe', 'GROUP' => 'SUPPORT' ), array( 'NAME' => 'James Doe', 'GROUP' => 'GUEST' ), array( 'NAME' => 'Jane Doe', 'GROUP' => 'GUEST' ), ); ? $page->assign( 'users', $users ); ? $page->output(); ? ?>模板: begin_end.html:
<style type="text/css"> .col0 { background-color: #D0D0D0; } .col1 { background-color: #F0F0F0; } </style> ? <table border="1" cellpadding="2" cellspacing="0"> <tr> <th> No </th> <th> Username </th> <th> Usergroup </th> </tr> ? <!-- BEGIN users --> ? <tr class="col{ROWBIT}"> <td> {ROWCNT} </td> <td> {NAME} </td> <td> {GROUP} </td> </tr> ? <!-- END users --> ? </table> The Result that is created by the PHP Script is displayed in the following box:
Ouput:
include
所有在主模板中可用的功能性的東西在子模板中均可使用
語法如下:
<!– INCLUDE templatename.html –>
include.php:
<?php require_once "class.quickskin.php"; $page = new QuickSkin("include.html"); ? $page->assign( 'header', 'This is the header' ); $page->assign( 'body', 'This is the body' ); $page->assign( 'footer', 'This is the foter' ); ? $page->output(); ?>模板: include.html:
<!-- INCLUDE header.html --> {body} <!-- INCLUDE footer.html -->header.html
<h1>{header}</h1>footer.html
<br> {footer}輸出結果:
<h1>This is the header</h1> This is the body <br> This is the footer轉載于:https://www.cnblogs.com/imvkmark/archive/2010/02/24/2291520.html
總結
以上是生活随笔為你收集整理的QuickSkin简单学习--控制结构的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 淘宝自动抢购脚本「建议收藏」(淘宝海外全
- 下一篇: TextMate介绍[通俗易懂]