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>
  • 相关阅读:
    3配置
    1开机初始化配置
    shell <<EOF
    Sun SPARC Enterprise M5000 启动步骤
    CISCO MDS – Useful ‘Show’ Commands
    oracle 内存不足处理
    mysql 日志类型
    MySQL 学习
    抓取进程中包括其所有线程的iowait时间
    每天网络半小时(MAC数据包在哪里合并的)
  • 原文地址:https://www.cnblogs.com/fengju/p/6174111.html
Copyright © 2011-2022 走看看