TP5 的 模板view 语法 整理 供自己速查

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index view</title>
    <link rel="stylesheet" type="text/css" href="__STATIC__/demo.css">
</head>
<body>
    <!-- 变量 -->
<!--     <p>STATIC</p>
    <p>{$key}</p>
    <p>{$key2}</p>
    <p>{$key3}</p> -->

    <!-- 模板常量 -->
 <!--    <p>{$Think.server.HTTP_HOST}</p>
    <p>{$Think.env.PHP_STATUS}</p>
    <p>{$Think.session.email}</p>
    <p>{$Think.cookie.ckemail}</p>

    <p>{$Think.get.ide}</p>
    <p>{$Think.request.id}</p>
    <p>{$Think.post.id}</p>

    <p>{$Think.const.APP_PATH}</p>
    <p>{$Think.APP_PATH}</p> -->

<!-- 可以直接php 但不推荐  调试的时候可以用 0.0.0.0.0.0-->
 <!--    <?php
        $a = 10;
        $b = 20;
        if($a>$b){
            #code...
        }
    ?> -->

<!-- 函数处理 -->
<!--     <h2>{$email} : {$email|md5}</h2>
    <h2>{$email} : {$email|substr=0,8}</h2>
    <h2>{$email} : {$email|substr=###,0,8}</h2>
 -->
    <!-- 运算 -->
<!--     <p>{$a*$b}</p>
    <p>{$a+$b}</p>
    <p>{$b%$c}</p>
    <p>{++$a}</p>
    <p>{--$a}</p>
 -->
<!-- 默认值 -->
    <!-- <h2>{$emails|default='1111111@qq.com'}</h2> -->

<!-- 循环  -->
    <!-- foreach -->
<!--     {foreach $list as $data}
        <p>{$data.name}</p>
    {/foreach}

    {foreach name="list" item='data' key='i'}
        <p>{$data.email}</p>
    {/foreach} -->

    <!-- for -->
<!--     {for start="1" end="10" step="2" name='j'}
        <p>{$j}</p>
    {/for} -->

    <!-- volist -->
<!--     {volist name="list" id="vo" offset='1' length='1' mod='2' key='k'}
        <p>{$vo.name}</p>
        <p>{$vo.email}</p>
    {/volist} -->

<!-- 比较标签 -->
<!-- {eq name='a' value="$b"}
ok
{else/}
ko
{/eq} -->
<!-- equal neq notequal gt egt lt elt 语法同上-->


<!-- 条件标签 get传值?level http://course.me/index/index/openview?level=3 -->
	 {if condition="($Think.get.level==1) AND ($Think.get.id==10)"}
            <p>if true</p>
    {else/}
            <p>if false</p>
    {/if}

    {switch name="Think.get.level"}
        {case value='1|2'}<p>普通会员</p>{/case}
        {case value='3'}<p>青铜会员</p>{/case}
        {case value='4'}<p>白银会员</p>{/case}
        {case value='5'}<p>黄金会员</p>{/case}
        {case value='6'}<p>砖石会员</p>{/case}
        {default /}<p>游客</p>
    {/switch}

    <!-- type in notin between -->
    {range name="Think.get.level" value="1,2,3" type="in"}

        <p>当前level在1,2,3中一个</p>
    {else/}
        <p>当前level不在1,2,3中一个</p>
    {/range}

    {in name="Think.get.level" value="1,2,3"}
        <p>当前level在1,2,3中一个</p>
    {else/}
        <p>当前level不在1,2,3中一个</p>
    {/in}

    {defined name = "APP_PATH_NO"}
        <p>APP_PATH_NO已定义</p>
    {else/}
        <p>APP_PATH_NO未定义</p>
    {/defined}


<!-- literal标签 防止js代码被解析 -->
{literal}
<script type="text/javascript">
    {$email}
</script>
{/literal}

</body>
</html>

记录你我
请先登录后发表评论
  • latest comments
  • 总共0条评论