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! ";
}
}
?>
|