Smarty simple template variable output method original, smartyfont

Source: Internet
Author: User
Tags smarty template

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.