Smarty is a template engine for PHP. K+5S7wFDZ
More specifically, it facilitates a manageable way to separate application logic and content from its presentation. i/N4uq}'A<
This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person. I0trHrX9
For example, let's say you are creating a web page that is displaying a newspaper article. The article headline, tagline, author and body are content elements, they contain no information about how they will be presented. They are passed into Smarty by the application, then the template designer edits the templates and uses a combination of HTML tags and template tags to format the presentation of these elements (HTML tables, background colors, font sizes, style sheets, etc.) $@<qaR{t \
One day the programmer needs to change the way the article content is retrieved (a change in application logic.) This change does not affect the template designer, the content will still arrive in the template exactly the same. Yq-Nk:H|
Likewise, if the template designer wants to completely redesign the templates, this requires no changes to the application logic. Therefore, the programmer can make changes to the application logic without the need to restructure templates, and the template designer can make changes to templates without breaking application logic. ^R',P(@oL
r<,W{Va
Smarty是一个php模板引擎. x2(!r3a
更准确的说,它分开了逻辑程序和外在的内容,提供了一种易于管理的方法 k\W%^Z
可以描述为应用程序员和美工扮演了不同的角色,因为在大多数情况下 ,他们不可能是同一个人. J*?BwmD'8
例如,你正在创建一个用于浏览新闻的网页,新闻标题,标签栏,作者和内容等都是内容要素,他们并不包含应该怎样去呈现.在Smarty的程序里,这些被忽略了.模板设计者们编辑模板,组合使用html标签和模板标签去格式化这些要素的输出(html表格,背景色,字体大小,样式表,等等) ~0aWjMc(>
有一天程序员想要改变文章检索的方式(也就是程序逻辑的改变).这个改变不影响模板设计者,内容仍将准确的输出到模板. FTZ][
同样的,哪天美工吃多了想要完全重做界面,也不会影响到程序逻辑. pCS2sq8RC
因此,程序员可以改变逻辑而不需要重新构建模板,模板设计者可以改变模板而不影响到逻辑.(靠~,这么简单的东东讲了那么多,老外和唐僧有一打.) !$P+hX`
_R-[*ucq
Now for a short word on what Smarty does NOT do. 1:%HE*r
Smarty does not attempt to completely separate logic from the templates. RLBjl%Q>
There is no problem with logic in your templates under the condition that this logic is strictly for presentation. E~Eh'>Y(B
A word of advice: keep application logic out of the templates, and presentation logic out of the application. 28J
;9
This will most definately keep things manageable and scalable for the foreseeable future. O)NEt
(,<&H;,8
现在简短的说一下什么是smarty不做的. (jv!q@@2C.
smarty不尝试将逻辑完全和模板分开. *)+1BYMo
如果逻辑程序严格的用于页面表现,那么它在模板里不会出现问题. Cg[]y1Ne
有个建议:让应用程序逻辑远离模板, 页面表现逻辑远离应用程序逻辑. 8@S7_x
这将在以后使内容更容易管理,程序更容易升级. b<o Uy
!m)P*Lw
One of the unique aspects about Smarty is the template compling. -S5M>W.Qb{
This means Smarty reads the template files and creates PHP scripts from them. __<