PHP - Smarty模板引擎 - Manual手册 - Chapter 7. Built-in Functions第7章 内建函数 - {config_load}用于从一个配置文件加载配置变量到模板中

 

PHP - Smarty模板引擎 - Manual手册 - Chapter 7. Built-in Functions第7章 内建函数 - {config_load}用于从一个配置文件加载配置变量到模板中

{config_load}

{config_load} is used for loading config #variables# from a configuration file into the template.

Attribute NameTypeRequiredDefaultDescription
filestringYesn/aThe name of the config file to include
sectionstringNon/aThe name of the section to load
scopestringnolocal How the scope of the loaded variables are treated, which must be one of local, parent or global. local means variables are loaded into the local template context. parent means variables are loaded into both the local context and the parent template that called it. global means variables are available to all templates.
globalbooleanNoNo Whether or not variables are visible to the parent template, same as scope=parent. NOTE: This attribute is deprecated by the scope attribute, but still supported. If scope is supplied, this value is ignored.

Example 7-3. {config_load}

The example.conf file.

#this is config file comment

# global variables
pageTitle = "Main Menu"
bodyBgColor = #000000
tableBgColor = #000000
rowBgColor = #00ff00

#customer variables section
[Customer]
pageTitle = "Customer Info"

and the template

{config_load file="example.conf"}

<html>
<title>{#pageTitle#|default:"No title"}</title>
<body bgcolor="{#bodyBgColor#}">
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
<tr bgcolor="{#rowBgColor#}">
<td>First</td>
<td>Last</td>
<td>Address</td>
</tr>
</table>
</body>
</html>

Config Files may also contain sections. You can load variables from within a section with the added attribute section. Note that global config variables are always loaded along with section variables, and same-named section variables overwrite the globals.

Note: Config file sections and the built-in template function called {section} have nothing to do with each other, they just happen to share a common naming convention.

Example 7-4. function {config_load} with section

{config_load file='example.conf' section='Customer'}

<html>
<title>{#pageTitle#}</title>
<body bgcolor="{#bodyBgColor#}">
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
<tr bgcolor="{#rowBgColor#}">
<td>First</td>
<td>Last</td>
<td>Address</td>
</tr>
</table>
</body>
</html>

See $config_overwrite to create arrays of config file variables.

See also the config files page, config variables page, $config_dir, get_config_vars() and config_load().

[PHP - Smarty模板引擎 - Manual手册 - Chapter 7. Built-in Functions第7章 内建函数 - {config_load}用于从一个配置文件加载配置变量到模板中 - 文档]

http://www.smarty.net/manual/en/language.function.config.load.php

[PHP - Smarty模板引擎 - 官方网站]

http://smarty.php.net/

[PHP - Smarty模板引擎 - 下载地址]

当前版本 2.6.18, http://smarty.php.net/do_download.php?download_file=Smarty-2.6.18.tar.gz

全部列表, http://smarty.php.net/download.php

[PHP - Smarty模板引擎 - 相关论坛]

http://php.board.newsmth.net/
http://forum.csdn.net/SList/PHP/
http://www.phpinsider.com/smarty-forum/
http://news.php.net/php.smarty.general
http://news.php.net/php.smarty.dev
http://news.php.net/php.smarty.cvs

[PHP - Smarty模板引擎 - 关键词]

smarty

[PHP - Smarty模板引擎 - Manual手册]

借助cycle实现循环输出值, http://smarty.php.net/manual/en/language.function.cycle.php

Smarty的cat函数, http://smarty.php.net/manual/en/language.modifier.cat.php

Smarty的upper函数, http://smarty.php.net/manual/en/language.modifier.upper.php

[PHP - Smarty模板引擎 - Manual手册 - Chapter 3. Basic Syntax第3章 基础语法]

Comments注释, http://smarty.php.net/manual/en/language.basic.syntax.php#language.syntax.comments
Math数学运算, http://smarty.php.net/manual/en/language.math.php

[PHP - Smarty模板引擎 - Manual手册 - Chapter 5. Variable Modifiers第5章 变量修饰符]

cat将值连接到给定变量之后, http://smarty.php.net/manual/en/language.modifier.cat.php

upper将字符串转换成大写字母, http://smarty.php.net/manual/en/language.modifier.upper.php

escape转义修饰符, http://smarty.php.net/manual/en/language.modifier.escape.php

[PHP - Smarty模板引擎 - Manual手册 - Chapter 7. Built-in Functions第7章 内建函数]

{config_load}用于从一个配置文件加载配置变量到模板中, http://www.smarty.net/manual/en/language.builtin.functions.php

{foreach},{foreachelse}用于像访问序数数组一样访问关联数组, http://smarty.php.net/manual/en/language.function.foreach.php

{strip}在显示之前删除每行前后多余的空格和回车字符, http://smarty.php.net/manual/en/language.function.strip.php

[PHP - Smarty模板引擎 - Manual手册 - Chapter 8. Custom Functions第8章 自定义函数]

{assign}用于在模板执行过程中设置模板变量, http://smarty.php.net/manual/en/language.custom.functions.php#language.function.assign

{counter}计数器, http://smarty.php.net/manual/en/language.custom.functions.php

[PHP - Smarty模板引擎 - Manual手册 - 第13章 Smarty类方法]

register_function()动态注册模板函数插件, http://smarty.php.net/manual/en/api.register.function.php

assign_by_ref()按引用赋值, http://smarty.php.net/manual/en/api.assign.by.ref.php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值