聪明的模板引擎

时间:2011-03-31 06:36:25

标签: smarty

我有一个使用php编写的网页,但现在需要将它们转换为智能模板引擎。 我是聪明的模板引擎的新手。我发现smarty.net文件很难。是否有任何书籍或网站,我可以从中学习聪明。 我需要一个小片段来插入功能。

1 个答案:

答案 0 :(得分:1)

我认为smarty.net文档是开始使用Smarty模板引擎的最佳点。

大多数教程都基于我认为的文档。

要快速启动,您只需要Smarty基类:

// Require base class
require_once('Smarty.class.php');

// create new Smarty instance
$smarty = new Smarty();

// define Smarty directories
$smarty->template_dir = '/web/www.example.com/guestbook/templates/';
$smarty->compile_dir  = '/web/www.example.com/guestbook/templates_c/';
$smarty->config_dir   = '/web/www.example.com/guestbook/configs/';
$smarty->cache_dir    = '/web/www.example.com/guestbook/cache/';

// define a template variable, which will be shown in your template
$smarty->assign('greeting', 'Hello World!');

// force your php script to show your template file
$smarty->display('template.html');

这就是PHP文件中所需的一切。

在Smarty的默认配置中,您可以使用

显示模板变量问候语
My greeting message: {$greeting}

如果您通过浏览器打开PHP文件,您将看到:我的问候语:Hello World!

有关详细信息,您真的应该阅读官方的Smarty文档!