Home >Backend Development >PHP Tutorial >How the smarty template engine obtains data from the configuration file, smarty template_PHP tutorial
The example in this article describes how the smarty template engine obtains data from the configuration file. Share it with everyone for your reference. The details are as follows:
When you do not want the value of a variable to be hard-coded in the program, you can write the variable into the configuration file and obtain it from it (common configuration style).
Step one: First write a configuration file, such as db.conf of the database. You can write the suffix name conf casually, or db.ini. The format of the content in the file needs to be fixed: key="value". There is no need to add a semicolon or anything after each line. Just return to the country and change the line, such as:
Configuration file: db.conf
Template file: temp.tpl
Use {config_load file="db.conf"} to import the file. Note that if you write a relative path, it must be viewed based on the page you are visiting. For example, here, temp.tpl is placed in the templates directory, and db.conf is placed on the same level as the templates directory. However, since the file index.php accessed by the browser is on the same level as db.conf, when referencing it, write {config_load directly. file="db.conf"} .
{#host#}
{#username#}
Browser access: index.php
Different from getting variable data from php, there is no need to assign it here, but it is loaded directly in the template file
I hope this article will be helpful to everyone’s smarty programming design.