smarty基礎應用源碼

來源:互聯網
上載者:User

index.php

<?php/*//直接在本檔案中配置//庫檔案包含define('SMARTY_DIR','D:/APMServ5.2.6/www/htdocs/smartydemo/smarty/');require(SMARTY_DIR.'smarty.class.php');//配置$smarty = new Smarty;$smarty->compile_dir = SMARTY_DIR.'templates_c/';$smarty->cache_dir = AMARTY_DIR.'cache/';$smarty->template_dir = 'templates/';$smarty->config_dir = 'config/';$this->caching = true;//變數傳值$smarty->assign('name', 'phf');//顯示模板檔案$smarty->display('index.tpl');//$smarty->display('index.tpl', 2);//多份緩衝*//* //取出產生的檔案$file = $smarty->fetch('index.tpl');echo $file;*//*//單個檔案的cache時間設定$smarty->caching = 2; // lifetime is per cache$smarty->cache_lifetime = 300;$smarty->display('index.tpl');*/// 實初化配置的進一步類封裝require_once('smartydemo.class.php');$smarty = new Smarty_demo;$smarty->assign('name', 'phf');//$smarty->display('index.tpl');$smarty->display('index.tpl', 2);

smartydemo.class.php

<?php//define('SMARTY_DIR','D:/APMServ5.2.6/www/htdocs/smartydemo/smarty/');require(SMARTY_DIR.'smarty.class.php');class Smarty_demo  extends Smarty{function __construct(){Smarty::__construct();$this->compile_dir = SMARTY_DIR.'templates_c/';$this->cache_dir = SMARTY_DIR.'cache/';$this->template_dir = 'templates/';$this->config_dir = 'config/';$this->caching = true;$this->cache_lifetime = 1;$this->assign('app_name','smartydemo');}}

index.tpl

{* smarty *}<h1>{$app_name}</h1>hello {$name}!;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.