codecamp

Smarty成员方法:createTemplate()

Name

createTemplate() — 创建模板对象

说明

Smarty_Internal_Template createTemplate(string template,
                                        object parent);

Smarty_Internal_Template createTemplate(string template,
                                        array data);

Smarty_Internal_Template createTemplate(string template,
                                        string cache_id,
                                        string compile_id,
                                        object parent);

Smarty_Internal_Template createTemplate(string template,
                                        string cache_id,
                                        string compile_id,
                                        array data);

创建一个模板对象,可以让display或者fetch来使用。 参数如下:

  • template必须是 模板资源类型和路径。

  • cache_id is an optional parameter. You can also set the $cache_id variable once instead of passing this to each call to this function. It is used in the event that you want to cache different content of the same template, such as pages for displaying different products. See also the caching section for more information.

  • compile_id is an optional parameter. You can also set the $compile_id variable once instead of passing this to each call to this function. It is used in the event that you want to compile different versions of the same template, such as having separate templates compiled for different languages.

  • parent is an optional parameter. It is an uplink to the main Smarty object, a user-created data object or to another user-created template object. These objects can be chained. The template can access only variables assigned to any of the objects in the parent chain.

  • data is an optional parameter. It is an associative array containing the name/value pairs of variables which get assigned to the object.

Example 14.18. createTemplate()

<?php
include('Smarty.class.php');
$smarty = new Smarty;

// 创建模板对象
$tpl = $smarty->createTemplate('index.tpl');

// 赋值
$tpl->assign('foo','bar');

// 显示模板
$tpl->display();
?>


参见 display(), 和 templateExists().

Smarty成员方法:createData()
Smarty成员方法:disableSecurity()
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

I.Smarty基础

1.Smart是什么?

II.Smarty模板设计师篇

6.Smarty复合修饰器

9.Smarty配置文件

10.Smarty调试控制台

III. 程序开发者篇

11. Smarty字符集编码

12.Smarty常量

13.Smarty成员变量

14.Smarty成员方法

17.Smarty高级特性

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }