Home > Article > Backend Development > PHP simple smarty entry program example, smarty entry example_PHP tutorial
The example in this article tells the php simple smarty entry program. Share it with everyone for your reference. The details are as follows:
First there are 3 folders configs, templates, templates_c. There is a configuration file in the configs folder: test.conf, code:
title = Welcome to Smarty! cutoff_size = 40 [setup] bold = true
There is a template file in templates: test.htm:
<html> <head> <title>Smarty Test</title> </head> <body> <H1>Hello, {$Name}</H1> </body> </html>
php file code:
<?php require 'libs/Smarty.class.php'; //包含Smarty类库文件 $smarty = new Smarty; //创建一个新的Smarty对象 $smarty->assign("Name","Simon"); //对模版中的变量赋值 $smarty->display('test.htm'); //显示页面 ?>
The page code displayed after running:
<html> <head> <title>Smarty Test</title> </head> <body> <H1>Hello, Simon</H1> </body> </html>
After running, a php file is also generated in the templates_c folder:
<?php /* Smarty version 2.6.22, created on 2009-03-19 13:20:00 compiled from test.htm */ ?> <html> <head> <title>Smarty Test</title> </head> <body> <H1>Hello, <?php echo $this->_tpl_vars['Name']; ?> </H1> </body> </html>
This file is the effect displayed when browsing.
I hope this article will be helpful to everyone’s PHP programming design.