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>
  • 相关阅读:
    腾讯// 反转字符串
    腾讯//Multiply Strings 字符串相乘
    腾讯//盛最多水的容器
    腾讯//删除排序数组中的重复项
    腾讯//删除排序数组中的重复项
    C语言中的预处理命令
    Python十大应用领域与就业方向
    Python的主要应用领域及应用场景
    Git命令_git status
    Git命令_git add快速添加文件到暂存区
  • 原文地址:https://www.cnblogs.com/fengju/p/6174111.html
Copyright © 2011-2022 走看看