zoukankan      html  css  js  c++  java
  • smarty笔记一

    1、从php分配变量

    index.php:
    
    $smarty = new Smarty;
    $smarty->assign('Contacts',
     array('fax' => '555-222-9876',
     'email' => 'zaphod@slartibartfast.com',
     'phone' => array('home' => '555-444-3333',
     'cell' => '555-111-1234')));
    $smarty->display('index.tpl');
    
    index.tpl:
    
    {$Contacts.fax}<br>
    {$Contacts.email}<br>
    {* you can print arrays of arrays as well *}
    {$Contacts.phone.home}<br>
    {$Contacts.phone.cell}<br>
    
    OUTPUT:
    
    555-222-9876<br>
    zaphod@slartibartfast.com<br>
    555-444-3333<br>
    555-111-1234<br>
    2、从php分配变量
    index.php:
    
    $smarty = new Smarty;
    $smarty->assign('Contacts',
     array('555-222-9876',
     'zaphod@slartibartfast.com',
     array('555-444-3333',
     '555-111-1234')));
    $smarty->display('index.tpl');
    
    index.tpl:
    
    {$Contacts[0]}<br>
    {$Contacts[1]}<br>
    {* you can print arrays of arrays as well *}
    {$Contacts[2][0]}<br>
    {$Contacts[2][1]}<br>
    
    OUTPUT:
    
    555-222-9876<br>
    zaphod@slartibartfast.com<br>
    555-444-3333<br>
    555-111-1234<br>
    3、从php分配变量
    name: {$person->name}<br>
    email: {$person->email}<br>
    
    OUTPUT:
    
    name: Zaphod Beeblebrox<br>
    email: zaphod@slartibartfast.com<br>
    4、从配置文件引用的变量 
    foo.conf:
    
    pageTitle = "This is mine"
    bodyBgColor = "#eeeeee"
    tableBorderSize = "3"
    tableBgColor = "#bbbbbb"
    rowBgColor = "#cccccc"
    
    index.tpl:
    
    {config_load file="foo.conf"}
    <html>
    <title>{#pageTitle#}</title>
    <body bgcolor="{#bodyBgColor#}">
    <table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
    <tr bgcolor="{#rowBgColor#}">
    	<td>First</td>
    	<td>Last</td>
    	<td>Address</td>
    </tr>
    </table>
    </body>
    </html>
    
    index.tpl: (alternate syntax)
    
    {config_load file="foo.conf"}
    <html>
    <title>{$smarty.config.pageTitle}</title>
    <body bgcolor="{$smarty.config.bodyBgColor}">
    <table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
    <tr bgcolor="{$smarty.config.rowBgColor}">
    	<td>First</td>
    	<td>Last</td>
    	<td>Address</td>
    </tr>
    </table>
    </body>
    </html>
    
    
    OUTPUT: (same for both examples)
    
    <html>
    <title>This is mine</title>
    <body bgcolor="#eeeeee">
    <table border="3" bgcolor="#bbbbbb">
    <tr bgcolor="#cccccc">
    	<td>First</td>
    	<td>Last</td>
    	<td>Address</td>
    </tr>
    </table>
    </body>
    </html>
  • 相关阅读:
    简洁又漂亮的单网页404页源码(html格式404源码)
    运行bee run之后出现的错误以及解决方法
    window beego 安装出现的错误
    golang gin框架 使用swagger生成api文档
    go语言切片作为函数参数
    Go中函数接收器不能改变接收者的地址
    docker 删除none镜像
    redis下载安装
    git切换分支
    angular自定义验证器添加入模板驱动表单
  • 原文地址:https://www.cnblogs.com/fengju/p/6174111.html
Copyright © 2011-2022 走看看