配置文件

来源:互联网 发布:cc攻击 php网站防御 编辑:程序博客网 时间:2024/06/08 10:07

1、配置文件有利于设计者管理文件中的模板全局变量

2、配置文件是通过内建函数载入到模板中 <{  config_load file="文件地址"  }>

                 foo.conf:                                           //#注释部分

                       pageTitle = "This is mine"        //当变量中有空格时,需要用引号引着,没有空格时 ,可不引 。" " " 是定界符,定界符中可以是任意格式

                       bodyBgColor = "#eeeeee"         

                       tableBorderSize = "3"

                       tableBgColor = "#bbbbbb"

                       rowBgColor = "#cccccc"

                        [mycolor]                        // [  ]是section的内容 当写section时,需顶格写

                       bgcolor = #000000

            index.tpl:

                      {config_load file="foo.conf" section='mycolor'}

                     <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>

             index.tpl:

                    {config_load file="foo.conf"}

                        <html>

                              <title>{$smarty.config.pageTitle}</title>

                          <body bgcolor="{$smarty.config.bodyBgColor}">

                              <table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">

                                 <tr bgcolor="{$smarty.config.rowBgColor}"

                                         <td>First</td><td>Last</td><td>Address</td>

                                        </tr>

                               </table>

                   </body>

                   </html>


原创粉丝点击