This article mainly introduces the simple getting started instance of smarty, including the usage of the configuration file and the use of the template file, which is of great practical value, for more information about how to use smarty, see this document. Share it with you for your reference. The specific analysis is as follows:
After smarty creates a configuration file and a display file, the configuration file display file is separated, so that the artist and the development work can be perfectly separated.
Configuration page code: index. php
The Code is as follows:
<? Php
@ Header ("Content-type: text/html; charset = UTF-8 ");
Require '../libs/Smarty. class. php ';
$ My = new Smarty;
$ My-> template_dir = 'templates /';
$ My-> compile_dir = 'templates _ c /';
$ My-> config_dir = 'configs /';
$ My-> cache_dir = 'cache /';
$ My-> assign ('content', 'Welcome to arrival ');
$ My-> assign ('mylife', array ("life", "eat", "dream", "liangfeng "));
$ My-> display('kk.html '); // display kk.html in the smartydirectory
?>
Kk.html
The Code is as follows:
Untitled document
{$ Content}
{Section name = truelife loop = $ mylife}
{$ Mylife [truelife]}
{/Section}
I hope this article will help you design your smarty program.