How to implement a multi-template website using smarty in php

Source: Internet
Author: User

How to implement a multi-template website using smarty in php

Template model1.htm code:

1

2

3

4

5

6

7

8

9

10

11

12

13

<Html>

<Head>

<Title> TEMPLATE 1 </title>

</Head>

<Body>

<A href = "? Model = 1 "mce_href = "? Model = 1 "> TEMPLATE 1 </a> |

<A href = "? Model = 2 "mce_href = "? Model = 2 "> template 2 </a> |

<A href = "? Model = 3 "mce_href = "? Model = 3 "> TEMPLATE 3 </a>

<P align = CENTER> <font color = RED >{$ title} </font> </p>

<Hr>

{$ Content}

</Body>

</Html>

Template model2.htm code:

1

2

3

4

5

6

7

8

9

10

11

12

13

<Html>

<Head>

<Title> template 2 </title>

</Head>

<Body>

<A href = "? Model = 1 "mce_href = "? Model = 1 "> TEMPLATE 1 </a> |

<A href = "? Model = 2 "mce_href = "? Model = 2 "> template 2 </a> |

<A href = "? Model = 3 "mce_href = "? Model = 3 "> TEMPLATE 3 </a>

<P align = CENTER> <font color = GREEN >{$ title} </font> </p>

<Hr>

{$ Content}

</Body>

</Html>

Template model3.htm code:

1

2

3

4

5

6

7

8

9

10

11

12

13

<Html>

<Head>

<Title> TEMPLATE 3 </title>

</Head>

<Body>

<A href = "? Model = 1 "mce_href = "? Model = 1 "> TEMPLATE 1 </a> |

<A href = "? Model = 2 "mce_href = "? Model = 2 "> template 2 </a> |

<A href = "? Model = 3 "mce_href = "? Model = 3 "> TEMPLATE 3 </a>

<P align = CENTER> <font color = BLUE >{$ title} </font> </p>

<Hr>

{$ Content}

</Body>

</Html>

Php page implementation:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<? Php

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

$ Smarty = new Smarty; // create a new Smarty object

$ Title = "Test ";

$ Content = "This is a test! ";

$ Smarty-> assign ("title", $ title); // assign values to variables in the template

$ Smarty-> assign ("content", $ content); // assign values to variables in the template

If (! Isset ($ _ GET ['model']) // select different templates based on parameters

{

$ Smarty-> display('model1.htm ');

}

Else

{

If (file_exists ('templates/'.'model'.w._getw.'model'}.'.htm '))

// Determine whether the template file exists

{

$ Smarty-> display('model'.w._getw.'model'{.'.htm ');

}

Else

{

Echo "the template parameters are incorrect! ";

}

}

?>

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.