首页 > 其他类 > smarty简易教程

smarty简易教程

2010年7月30日 作者:water
  1. 下载解压到wordir,一般采用最新的稳定版即可,目前是2.6.26
  2. 在php里面
    • require ‘smarty/libs/Smarty.class.php’;
    • $smarty = new Smarty;
    • 配置参数
      • $smarty->template_dir =”smarty/templates/templates”;
      • $smarty->compile_dir =”smarty/templates/templates_c”;
      • $smarty->config_dir = “smarty/templates/config”;
      • $smarty->cache_dir =”smarty/templates/cache”;
      • $smarty -> left_delimiter = “{{“;
      • $smarty -> right_delimiter = “}}”;
    • 变量赋值
      • $varname = ‘test data’;
      • $smarty->assign(‘htmlvar’, $varname,);
    • 调用模版显示$smarty->display(‘index.html’);
  3. 在html模版页面中
    • 变量传递:<html>这是从php传递过来的变量{{$htmvar}}</html>
    • 包含文件:{{include file=”header.html”}}
    • 判断语句:{{if $a == ”}} yes{{else}}no{{/if}}
    • 循环语句:{{section name=products loop=$product}}productname:{{$product.name}}{{/section}}

其他类

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.