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>
  • 相关阅读:
    spyder学习记录---如何调试
    Pycharm学习记录---同一目录下无法import明明已经存在的.py文件
    python库之matplotlib学习---图无法显示中文
    python之字典遍历方法
    python库之matplotlib学习---关于坐标轴
    将博客搬至CSDN
    C代码实现栈
    Android进程间通讯
    Android进程间通讯之messenger
    C代码实现非循环单链表
  • 原文地址:https://www.cnblogs.com/fengju/p/6174111.html
Copyright © 2011-2022 走看看