Home > Backend Development > PHP Tutorial > PHP simple smarty entry program example_PHP tutorial

PHP simple smarty entry program example_PHP tutorial

WBOY
Release: 2016-07-13 09:51:03
Original
814 people have browsed it

PHP simple smarty entry program example

First there are 3 folders configs, templates, templates_c. There is a configuration file in the configs folder: test.conf, code:

1

2

3

4

title = Welcome to Smarty!

cutoff_size = 40

[setup]

bold = true

1 2

3

4

1

2

3

4

5

6

7

8

Smarty Test

Hello, {$Name}

title = Welcome to Smarty! cutoff_size = 40

[setup]

bold = true

1

2

3

4

5

6

require 'libs/Smarty.class.php'; //包含Smarty类库文件

$smarty = new Smarty; //创建一个新的Smarty对象

$smarty->assign("Name","Simon"); //对模版中的变量赋值

$smarty->display('test.htm'); //显示页面

?>

There is a template file in templates: test.htm:

1

1

2

3

4

5

6

7

8

Smarty Test

Hello, Simon

2 3

4

5

1

2

3

4

5

6

7

8

9

10

11

12

13

/* Smarty version 2.6.22, created on 2009-03-19 13:20:00

compiled from test.htm */

?>

Smarty Test

Hello, _tpl_vars['Name']; ?>

6 7 8
Smarty Test

Hello, {$Name}

php file code:
1 2 3 4 5 6 <🎜>require 'libs/Smarty.class.php'; //Contains Smarty class library files<🎜> <🎜>$smarty = new Smarty; //Create a new Smarty object<🎜> <🎜>$smarty->assign("Name","Simon"); //Assign values ​​to variables in the template $smarty->display('test.htm'); //Display page ?>
The page code displayed after running:
1 2 3 4 5 6 7 8 Smarty Test

Hello, Simon

After running, a php file is also generated in the templates_c folder:
1 2 3 4 5 6 7 8 9 10 11 12 13 <🎜>/* Smarty version 2.6.22, created on 2009-03-19 13:20:00<🎜> <🎜>compiled from test.htm */<🎜> <🎜>?> Smarty Test

Hello, _tpl_vars['Name']; ?>

This file is the effect displayed when browsing.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1015338.htmlTechArticlephp simple smarty entry program example must first have 3 folders configs, templates, templates_c, in the configs folder There is a configuration file: test.conf, code: 1 2 3 4 title = W...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template