MVC开发模式以及Smarty模板引擎的使用(2)
发布时间:2020-12-25 10:29 所属栏目:53 来源:网络整理
导读:注释和变量的使用smarty.html !DOCTYPE htmlhtml lang="en"head meta charset="UTF-8"titleTitle/bodyh2 !-- 模板注释被*星号包围,而两边的星号又被定界符包围 -- {*$username*} {$username} h3 变量 {$age} hr 索
注释和变量的使用smarty.html <!DOCTYPE html> <html lang="en"head> meta charset="UTF-8"title>Title</bodyh2> <!-- 模板注释被*星号包围,而两边的星号又被定界符包围 --> {*$username*} {$username} h3 变量 {$age} hr 索引数组 arr1: {$arr1[1]} 关联数组 arr2: {$arr2['username']} {$arr2.username} 对象 Object: {var_dump($obj->getTemplateDir())} 变量的运算 {$var = 100} {$var} {$foo = $var + 200} {$foo} > {$foo} 保留变量的使用 $_GET: {var_dump($smarty.get)} $_POST: {var_dump($smarty.post)} $_REQUEST: {var_dump($smarty.request)} COOKIE: {var_dump($smarty.cookies)} SESSION: {var_dump($smarty.session)} SERVER: {var_dump($smarty.server)} ENV: {var_dump($smarty.env)} {time()} {$smarty.now} 加载配置文件后,配置文件中的变量需要用两个井号“#”包围或者是 smarty的保留变量$smarty.config.来调用 {config_load file='base.conf'} {#FONT_SIZE#} {$smarty.config.FONT_COLOR} html> 流程控制的使用loop.html >流程控制> 使用{if}处理分支结构 {$number = 200} {if $number === 100} gt {else if $number == 200} This number is 200 {else} This number is not 100 {/if} {$bool = false} {if not $bool} not {/if} {if $number is not even} odd {/if} {if $number is not odd} even {/if} {if $number mod 2 == 0} even {/if} {if $number is not odd by 3} odd {/if} 使用{for}处理循环 {for $i = 5 to 4 step 2} {$i} {forelse} no loop {/for} 使用{while}处理循环 {while $number > 195} {$number--} {/while} 使用{foreach}遍历数组 {foreach $arr2 as $key => $val} {if $val@first} {*break*} {continue} {/if} {$key}:{$val} {$val@key} {$val@index} {$val@iteration} {$val@first} {$val@last} {$val@show} {$val@total} {foreachelse} data does not exist {/foreach} 使用{section}遍历数组 {section name=key loop=$arr1} {$arr1[key]} {/section} {section name=key loop=$users2 step=-1 max=2} id: {$users[key].id} username: {$users[key].username} age: {$users[key].age} {$smarty.section.key.index} {$smarty.section.key.iteration} {$smarty.section.key.rownum} {$smarty.section.key.index_prev} {$smarty.section.key.index_next} {sectionelse} no loop {/section} > 常用标签函数的使用single_tag_func.html >常用标签函数的使用 {assign var="name" value="Jason"} {assign "name" "Jason Lee"} {$name} {append var="arr1" value=4 index="3"} {var_dump($arr1)} {ldelim}$name{rdelim} {html_checkboxes name="hobby" values=$hobby_ids output=$hobby_output selected=$hobby_ids} {html_checkboxes name="hobby" options=$options selected=$hobby_ids} {html_image width="50" height="50" alt="Google" href="http://www.google.com" file="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"} {html_options name="hobby" values=$hobby_ids output=$hobby_output selected=2} {html_options name="hobby" options=$options selected=2} {html_radios name="hobby" options=$options selected=2} {html_select_date} {html_select_time} {html_table loop=$arr1 cols=2 rows=3} {mailto address="86267659@qq.com" subject="test" text="给我发邮件" cc="123123@qq.com"} {math equation="x + y" x = 100 y = 200} > (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读