Simple php smarty entry program instance

Source: Internet
Author: User

Simple php smarty entry program instance

First, you must have three folders: configs, templates, and templates_c. In the configs folder, there is a configuration file: test. conf. The Code is as follows:

1

2

3

4

Title = Welcome to Smarty!

Cutoff_size = 40

[Setup]

Bold = true

Templates has the template file test.htm:

1

2

3

4

5

6

7

8

<Html>

<Head>

<Title> Smarty Test </title>

</Head>

<Body>

<H1> Hello, {$ Name} </H1>

</Body>

</Html>

PHP file code:

1

2

3

4

5

6

<? Php

Require 'libs/Smarty. class. php'; // contains the Smarty class library file

$ 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

?>

Page code displayed after running:

1

2

3

4

5

6

7

8

<Html>

<Head>

<Title> Smarty Test </title>

</Head>

<Body>

<H1> Hello, Simon </H1>

</Body>

</Html>

After running, a PHP file is generated in the templates_c Folder:

1

2

3

4

5

6

7

8

9

10

11

12

13

<? Php

/* Smarty version 2.6.22, created on 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 shows the effect of browsing.

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.