Get the App
SLTechnology News&Howtos  ›  Development  › 

How does the smarty template engine get data from configuration files

Shulou Source: shulou.com Published: 2022-06-03 19:54:02 11月12日 Update

This article mainly explains the "smarty template engine how to get data from the configuration file", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "smarty template engine how to get data from the configuration file" bar!

When the value of a variable does not want to be written dead in the program, you can write the variable to the configuration file and get it from it (common configuration styles).

The first step: first write a configuration file, such as the db.conf of the database, with the suffix conf as you like, 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. Go straight back to China and change the line, such as:

Configuration file: db.conf

The copy code is as follows:

Host = "localhost"

Username = "root"

Password = "123456"

Db_name = "liuyan"

Template file: temp.tpl

Use {config_load file= "db.conf"} to bring the file in. Note that if you write a relative path, look at it in terms of the page you visit. For example, here, temp.tpl is placed in the templates directory, and db.conf is placed on the same layer as the templates directory, but since the browser accesses the file index.php at the same level as db.conf, when referencing, write {config_load file= "db.conf"} directly.

The copy code is as follows:

{config_load file= "db.conf"}

Smarty variable operation, obtained from the configuration file

{# host#}

{# username#}

Browser access: index.php

Unlike getting variable data from php, you don't need to assign it with assign, but load it directly in the template file.

The copy code is as follows:

Thank you for reading, the above is the content of "smarty template engine how to get data from the configuration file", after the study of this article, I believe you have a deeper understanding of how the smarty template engine obtains data from the configuration file, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: File configuration data template code engine content variable learning browser directory browse different one line middle semicolon suffix object that is common Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker macOS OPPO Reno MariaDB