有用过SmartTemplate模板的兄弟吗?

xucailin 2003-10-17 08:15:35
能否讲讲他的长处与短处?
...全文
92 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
boystones 2003-10-18
  • 打赏
  • 举报
回复
缩短开发时间和基于对象
feel8 2003-10-18
  • 打赏
  • 举报
回复
英文太烂,官方网站上竟然没有找到文档:(
http://www.smartphp.net

What is SmartTemplate?SmartTemplate is a Template Engine that was designed to support large scale, web based applications.

What's so special about it?


Common template engines work like the following: Your PHP script specifies an HTML template and assigns some dynamic content to display. The template parser replaces all placeholders within the template with the assigned content and displays it to the user. This means a lot of string processing and regular expression work each time you want to display some content.

SmartTemplate works like a 'template compiler' that converts templates into executable PHP code and stores it for later reuse. The first time a new template is processed, all placeholders in the template are replaced by small PHP code elements that print the assigned content. The HTML template fragment <H3>{TITLE}</H3>, for example, is converted into something like <H3><?php echo $TITLE; ?></H3>. If you have assigned your content to the right variables, there is no need for any template parsing anymore. The only thing that has to be done is to include and execute the compiled template. This usually increases the execution time of the template engine dramatically.

SmartTemplate supports:
• Simple Scalar Substitution (Strings, etc.)
• Block Iterations (nested Arrays / BEGIN..END)
• Basic Control Structures (IF..ELSEIF..ELSE)
• Custom Extension (Output filters, uppercase, sprintf, etc.)
• Template Compilation (HTML templates are converted to executable PHP Code)
• Output Caching (Accelerates your applications by reusing page output)

Let's start with an easy example to show how to use SmartTemplate:

Usually the process of creating a webpage begins with a preview of the future result. Creating simple layouts this can be done using a webeditor like Dreamweaver or Homesite. For more complex page layouts one should always consider using a professional design tool like Photoshop, Paintshop Pro, Gimp etc.

Preview: Hello World!

Now we create the HTML source that generates a web page of our desired design:

HTML-Source (hello_world.html): <HTML>
<H3>Hello World!</H3>
</HTML>

Now the exciting step: The separation of content and design. We replace all dynamic content elements in the HTML-scource by placeholders. They get a unique name and an own tag around them so we can identify them later. The title Hello World! is replaced by a placeholder named TITLE. We mark this placeholder by embedding it in curly brackets, so the template parser can find it: {TITLE}. The HTML Template now looks like the following:

HTML-Template (hello_world.tpl.html): <HTML>
<H3>{TITLE}</H3>
</HTML>

To populate this template with content we have to:

Load the SmartTemplate Class
Instantiate a SmartTemplate Parser Object
Tell SmartTemplate which HTML-Template to use
Assign the content to it's associated placeholders
Process Template
Print result
The following PHP Script will do the required steps:

hello_world.php: <?php

require_once "class.smarttemplate.php";
$page = new SmartTemplate("hello_world.tpl.html");
$page->assign('TITLE', 'Hello World!');
$page->output();

?>


That's all - our Hello World example is ready to run.
shg918 2003-10-18
  • 打赏
  • 举报
回复
http://www.hiweed.com/down/xoops2/docs/smarty_manual.zip

建议下来读读
ppgo 2003-10-18
  • 打赏
  • 举报
回复
逻辑与内容分离,so cool,比phplib提供的模板功能强大
blueoxygen 2003-10-18
  • 打赏
  • 举报
回复
用phplib
smarty比phplib难(我感觉)
shg918 2003-10-18
  • 打赏
  • 举报
回复
长处么,易用,有个开关量,也就是可以通过加参数变换输出格式等等。短处:速度少慢,大名鼎鼎的xoops就是基于smatry开发的,还有iwpc网站发布系统
hcfyxy 2003-10-18
  • 打赏
  • 举报
回复
smarty还是很好用的,实现了代码、页面分离,我做的东西在intranet上跑,所以没感觉速度有什么影响。开发速度的确很快,只要设计好了,就是写代码初始化模板-〉$smarty->display('temp_name'),太easy了

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧