smarty模板引擎从配置文件中获取数据的方法,smarty模板
smarty模板引擎从配置文件中获取数据的方法,smarty模板
本文实例讲述了smarty模板引擎从配置文件中获取数据的方法。分享给大家供大家参考。具体如下:
当某个变量值,不希望在程序中写死时,就可以把该变量写到配置文件里,并从中获取(常见的配置样式)。
第一步:先写一个配置文件,如数据库的 db.conf,后缀名conf可以随便写,db.ini也行。文件中内容的格式需要固定:key="值",每一行后面不需要添加分号或者什么,直接回国换行,如:
配置文件:db.conf
复制代码 代码如下:
host = "localhost"
username = "root"
password = "123456"
db_name = "liuyan"
模板文件:temp.tpl
使用{config_load file="db.conf"} 将文件引入进来。注意,如果写相对路径的话,要以访问的页面来看。比如这里,temp.tpl放在templates目录下,db.conf是放在与templates目录同一层,但由于浏览器访问的文件index.php与db.conf同一层,所以,引用时,直接写 {config_load file="db.conf"} 。
复制代码 代码如下:
{config_load file="db.conf"}
smarty变量操作,从配置文件中获取
{#host#}
{#username#}
浏览器访问:index.php
与从php获取变量数据不同,这里不需要用assign分配,而在模板文件里直接加载
复制代码 代码如下:
//创建smarty对象
require_once("./libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->display("index.tpl");
?>
希望本文所述对大家的smarty程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP email templates: Customize and personalize your email content With the popularity and widespread use of email, traditional email templates can no longer meet people's needs for personalized and customized email content. Now we can create customized and personalized email templates by using PHP programming language. This article will show you how to use PHP to achieve this goal, and provide some specific code examples. 1. Create an email template First, we need to create a basic email template. This template can be an HTM

Regarding PPT masking, many people must be unfamiliar with it. Most people do not understand it thoroughly when making PPT, but just make it up to make what they like. Therefore, many people do not know what PPT masking means, nor do they understand it. I know what this mask does, and I don’t even know that it can make the picture less monotonous. Friends who want to learn, come and learn, and add some PPT masks to your PPT pictures. Make it less monotonous. So, how to add a PPT mask? Please read below. 1. First we open PPT, select a blank picture, then right-click [Set Background Format] and select a solid color. 2. Click [Insert], word art, enter the word 3. Click [Insert], click [Shape]

C++ template specializations affect function overloading and rewriting: Function overloading: Specialized versions can provide different implementations of a specific type, thus affecting the functions the compiler chooses to call. Function overriding: The specialized version in the derived class will override the template function in the base class, affecting the behavior of the derived class object when calling the function.

According to news on October 8, the U.S. auto market is undergoing a change under the hood. The previously beloved six-cylinder and eight-cylinder power engines are gradually losing their dominance, while three-cylinder engines are emerging. News on October 8 showed that the U.S. auto market is undergoing a change under the hood. The beloved six-cylinder and eight-cylinder power engines in the past are gradually losing their dominance, and the three-cylinder engine is beginning to emerge. In most people's minds, Americans love large-displacement models, and the "American big V8" has always been the Synonymous with American cars. However, according to data recently released by foreign media, the landscape of the U.S. auto market is undergoing tremendous changes, and the battle under the hood is intensifying. It is understood that before 2019, the United States

C++ is a programming language widely used in various fields. Its template metaprogramming is an advanced programming technique that allows programmers to transform types and values at compile time. Template metaprogramming is a widely discussed topic in C++, so questions related to it are quite common in interviews. Here are some common template metaprogramming interview questions in C++ that you may be asked. What is template metaprogramming? Template metaprogramming is a technique for manipulating types and values at compile time. It uses templates and metafunctions to generate based on types and values

In recent years, the template engine in PHP programming has become an important part of PHP development, making it easier for programmers to develop and manage pages. This article will introduce common template engines in PHP programming. SmartySmarty is a commonly used PHP template engine. It supports a series of functions such as cached templates, plug-in modules and custom functions. Smarty's syntax is very flexible and can solve the problem of combining PHP variables with HTML tags, making the PHP language more suitable for templated design. Moreover, S

The intelligent NPC created by Academician Huang in "Cyberpunk 2077" can already speak Chinese? Qubit's first-hand experience, witnessing NPCs conversing fluently in both Chinese and English, with natural expressions and movements, and matching mouth shapes... If there wasn't a screen in front of me, it would really feel like being there. . At this year's CES exhibition, Nvidia used its intelligent engine Avatar Cloud Engine (ACE) to make game NPCs "alive", which caused quite a shock. △The intelligent NPC displayed at CES uses ACE. The characters in the game can have realistic voice conversations with players, while showing vivid expressions and body movements without having to prepare a script in advance. At the time of its debut, there were Ubisoft, Tencent, NetEase, MiHoYo and other countries.

How to implement image template and mask processing in Vue? In Vue, we often need to perform some special processing on images, such as adding template effects or masks. This article will introduce how to use Vue to achieve these two image processing effects. 1. Image template processing When using Vue to process images, we can use the filter attribute of CSS to achieve template effects. The filter attribute adds graphic effects to the element, and the brightness filter can change the brightness of the picture. we can change
