Smarty simple template variable output method original, smartyfont
This article briefly describes the template variable output method of Smarty. We will share this with you for your reference. The details are as follows:
The config. inc. php configuration file is as follows:
Include_once ('smarty/smarty. class. php '); $ smarty = new Smarty (); $ smarty-> config_dir = "smarty/Config_File.class.php"; $ smarty-> caching = false; // whether to enable the cache $ smarty-> template_dir = ". /templates "; // template directory $ smarty-> compile_dir = ". /templates_c "; // compilation directory $ smarty-> cache_dir = ". /smarty_cache "; // cache directory $ smarty-> left_delimiter =" <{"; $ smarty-> right_delimiter ="}> ";
The index. php file is as follows:
Include ('./config. inc. php'); $ title = "php test title"; $ content = "smarty exercise! "; $ Newstext [] = array (" name "=>" php program test "," date "=>" 2015-08-01 "); $ newstext [] = array ("name" => "php video tutorial", "date" => "2015-08-02 "); $ newstext [] = array ("name" => "smarty learning", "date" => "2015-08-03"); $ row = array ("title", "name ", "Age"); $ smarty-> assign ("title", $ title); $ smarty-> assign ("row", $ row ); // pass multiple values in an array $ smarty-> assign ("shownewstext", $ newstext); // multiple values in a two-dimensional array $ smarty-> assign ("content ", $ content); $ smarty-> display('index.htm ');
The running result is as follows:
Test array: Title | Name | age -------------------------------------------------------------------------------- test content: smarty exercise! Loop news content: php program test-2015-08-01php video tutorial-2015-08-02smarty learning-2015-08-03
I hope this article will help you design php programs based on the Smarty template.