目录搜索
Smarty模板编译引擎I.开始第一章. 什么是Smarty?第二章. 安装要求基本安装扩展设置II.模板设计者篇第三章.基本语法注释函数属性第四章.变量从PHP分配的变量Associative arraysArray indexesObjects从配置文件读取的变量{$smarty}保留变量Request variables{$smarty.now}{$smarty.const}{$smarty.capture}{$smarty.config}{$smarty.section}{$smarty.template}第五章.变量调节器capitalizecount_characterscatcount_paragraphscount_sentencescount_wordsdate_formatdefaultescapeindentlowernl2brregex_replacereplacespacifystring_formatstripstrip_tagstruncateupperwordwrap第六章.组合修改器第七章.内建函数captureconfig_loadforeachincludeinclude_phpinsertifldelimliteralphpsectionindexindex_previndex_nextiterationfirstlastrownumloopshowtotalstrip第八章.自定义函数assigncountercycledebugevalfetchhtml_checkboxeshtml_imagehtml_optionshtml_radioshtml_select_datehtml_select_timehtml_tablemathmailtopopup_initpopuptextformat第九章.配置文件第十章.调试控制台III.模板程序员篇第十一章 常量SMARTY_DIR第十二章 变量$template_dir$compile_dir$config_dir$plugins_dir$debugging$debug_tpl$debugging_ctrl$global_assign$undefined$autoload_filters$compile_check$force_compile$caching$cache_dir$cache_lifetime$cache_handler_func$cache_modified_check$config_overwrite$config_booleanize$config_read_hidden$config_fix_newlines$default_template_handler_func$php_handling$security$secure_dir$security_settings$trusted_dir$left_delimiter$right_delimiter$compiler_class$request_vars_order$compile_id$use_sub_dirs$default_modifiers$default_resource_type第十三章.方法appendappend_by_refassignassign_by_refclear_all_assignclear_all_cacheclear_assignclear_cacheclear_compiled_tplclear_configconfig_loaddisplayfetchget_config_varsget_registered_objectget_template_varsis_cachedload_filterregister_blockregister_compiler_functionregister_functionregister_modifierregister_objectregister_outputfilterregister_postfilterregister_prefilterregister_resourcetrigger_errortemplate_existsunregister_blockunregister_compiler_functionunregister_functionunregister_modifierunregister_objectunregister_outputfilterunregister_postfilterunregister_prefilterunregister_resource第十四章.缓存Setting Up CachingMultiple Caches Per PageCache GroupsControlling Cacheability of Plugins' Output第十五章.高级特点ObjectsPrefiltersPostfiltersOutput FiltersCache Handler FunctionResourcesTemplates from $template_dirTemplates from any directoryTemplates from other sourcesDefault template handler function第十六章.以插件扩展SmartyHow Plugins WorkNaming ConventionsWriting PluginsTemplate FunctionsModifiersBlock FunctionsCompiler FunctionsPrefilters/PostfiltersOutput FiltersResourcesInsertsⅣ.高级特点第十七章.疑难解答Smarty/PHP errors第18章.使用技巧和经验Blank Variable HandlingDefault Variable HandlingPassing variable title to header templateDatesWAP/WMLComponentized TemplatesObfuscating E-mail Addresses第十九章. 相关资源第二十章. 漏洞
文字

Chapter 1. What is Smarty?

第一章.什么是Smaty?

Smarty is a template engine for PHP. More specifically, it facilitates a manageable way to separate application logic and content from its presentation. 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. 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.) 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. 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.

Smarty是一个php模板引擎。更准确的说,它分开了逻辑程序和外在的内容,提供了一种易于管理的方法。可以描述为应用程序员和美工扮演了不同的角色,因为在大多数情况下 ,他们不可能是同一个人。例如,你正在创建一个用于浏览新闻的网页,新闻标题,标签栏,作者和内容等都是内容要素,他们并不包含应该怎样去呈现。在Smarty的程序里,这些被忽略了。模板设计者们编辑模板,组合使用html标签和模板标签去格式化这些要素的输出(html表格,背景色,字体大小,样式表,等等)。有一天程序员想要改变文章检索的方式(也就是程序逻辑的改变)。这个改变不影响模板设计者,内容仍将准确的输出到模板。同样的,哪天美工吃多了想要完全重做界面,也不会影响到程序逻辑。因此,程序员可以改变逻辑而不需要重新构建模板,模板设计者可以改变模板而不影响到逻辑。

Now for a short word on what Smarty does NOT do. Smarty does not attempt to completely separate logic from the templates. There is no problem with logic in your templates under the condition that this logic is strictly for presentation. A word of advice: keep application logic out of the templates, and presentation logic out of the application. This will most definately keep things manageable and scalable for the foreseeable future.

现在简短的说一下什么是smarty不做的。smarty不尝试将逻辑完全和模板分开。如果逻辑程序严格的用于页面表现,那么它在模板里不会出现问题。有个建议:让应用程序逻辑远离模板, 页面表现逻辑远离应用程序逻辑。这将在以后使内容更容易管理,程序更容易升级。

One of the unique aspects about Smarty is the template compling. This means Smarty reads the template files and creates PHP scripts from them. Once they are created, they are executed from then on. Therefore there is no costly template file parsing for each request, and each template can take full advantage of PHP compiler cache solutions such as Zend Accelerator (http://www.zend.com) or PHP Accelerator (http://www.php-accelerator.co.uk).

Smarty的特点之一是"模板编译"。意思是Smarty读取模板文件然后用他们创建php脚本。这些脚本创建以后将被执行。因此并没有花费模板文件的语法解析,同时每个模板可以享受到诸如Zend加速器(http://www.zend.com) 或者PHP加速器(http://www.php-accelerator.co.uk)。这样的php编译器高速缓存解决方案。

Some of Smarty's features:

Smaty的一些特点:

  • It is extremely fast.
    非常非常的快!

  • It is efficient since the PHP parser does the dirty work.
    用php分析器干这个苦差事是有效的

  • No template parsing overhead, only compiles once.
    不需要多余的模板语法解析,仅仅是编译一次

  • It is smart about recompiling only the template files that have changed.
    仅对修改过的模板文件进行重新编译

  • You can make custom functions and custom variable modifiers, so the template language is extremely extensible.
    可以编辑'自定义函数'和自定义'变量',因此这种模板语言完全可以扩展

  • Configurable template delimiter tag syntax, so you can use {}, {{}}, <!--{}-->, etc.
    可以自行设置模板定界符,所以你可以使用{}, {{}}, <!--{}-->, 等等

  • The if/elseif/else/endif constructs are passed to the PHP parser, so the {if ...} expression syntax can be as simple or as complex as you like.
    诸如 if/elseif/else/endif 语句可以被传递到php语法解析器,所以 {if ...} 表达式是简单的或者是复合的,随你喜欢啦

  • Unlimited nesting of sections, ifs, etc. allowed.
    如果允许的话,section之间可以无限嵌套

  • It is possible to embed PHP code right in your template files, although this may not be needed (nor recommended) since the engine is so customizable.
    引擎是可以定制的.可以内嵌php代码到你的模板文件中,虽然这可能并不需要(不推荐)

  • Built-in caching support
    内建缓存支持

  • Arbitrary template sources
    独立模板文件

  • Custom cache handling functions
    可自定义缓存处理函数

  • Plugin architecture
    插件体系结构

上一篇:下一篇: