PHP Smarty Template Read configuration file variable

Source: Internet
Author: User
Tags smarty template

Configuration file Prep Knowledge

You can have the designer manage the global template variables in a file format.

One example is the color value of the administrative Template:

Usually if you need to change the color theme from the program, you need to find each template file and modify their color values.

With the configuration file, the color values are uniformly placed in the configuration file, you only need to modify this file.

# Global Variablespagetitle = "Main Menu" bodybgcolor = #000000tableBgColor = #000000rowBgColor = #00ff00 [customer]pagetit Le = "Customer Info" [login]pagetitle = "Login" focus = "username" Intro = "" "This is a value of that spans more than One line. You must enclose it in triple quotes. "" " # hidden section[. Database]host=my.example.comdb=addressbookuser=php-userpass=foobar

Configuration file

Configure the value of a variable

1. Can be quoted, but not required.

2. You can use single or double quotation marks.

3. If some values span more than one line, enclose them in three quotation marks ("" ").

Note   # (pound sign)

You can put any form of comment in the configuration file, but this is not a valid profile syntax.

Use # (pound sign) as the beginning of the comment line.

Paragraph []

The name of the paragraph is enclosed in [square brackets].

The paragraph name can be any character, but not include [ or ] symbol.


The top four values are global variables, that is, variables that are not within the paragraph. These global variables will always be loaded.


When a particular paragraph is loaded, the variables of the paragraph and the global variables will be loaded.

If both the global variable and the paragraph variable have the same variable, then the variable of the paragraph is used.

If you have the same two variables in the same paragraph, the last one will be used unless $config_overwrite the settings are closed.


Paragraph loaded into config_load section

<{config_load file= ". /config/my.conf "section =" Customer "}>


Configuration file Loading

    1. Built-in functions {config_load} to load,

    2. configLoad()loaded through a function.


Configure paragraph hiding[.hidden]

You can hide a variable or an entire paragraph by adding a dot (.) to the variable name or paragraph name, for example [.hidden] .

This tip saves some sensitive information in your program using a configuration file, but this information is useful when you don't want the template engine to use it. If you are a third party to modify the template, you can also ensure that they do not read the sensitive information when loading the configuration file


Configuration files are loaded from the database

such as $smarty->configLoad("db:my.conf") .


============================================================

from configuration file Gets the variable

1. Can be referenced by the pound sign to access such as #hash_marks #

<{#title #}>

2. Access by Smarty variable $smarty. config

<{$smarty .config.title}>


Complete example

Configuration file my.conf

Title= ' My first web ' bgcolor= ' white ' [index]name= ' Mr.yang ' [list]age=10

Template file Hello.tpl

Browser output

My first Webmr.yang


This article is from the "Jin Sha Harbor" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1843544

PHP Smarty Template Read configuration file variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.