Include Files With Smarty Template

Include Files With Smarty Templating

Smarty templates allow you two methods to include files. One method would be to use your '.php' file and the other is to use the '.tpl' file.

Method A

.php File

include("libs/smarty.class.php");
$smarty = new Smarty ();

$smarty->display("includes/header.inc.tpl"); 
$smarty->display("include.tpl"); 
$smarty->display("includes/footer.inc.tpl"); 


.tpl File

<p>
Here is some text from the main file. 
</p>


Method B

.php File

include("libs/smarty.class.php");
$smarty = new Smarty ();

//$smarty->display("includes/header.inc.tpl"); 
$smarty->display("include.tpl"); 
//$smarty->display("includes/footer.inc.tpl"); 


.tpl File

{include file='includes/header.inc.tpl'}
<p>
Here is some text from the main file. 
</p>
{include file='includes/footer.inc.tpl'}


Same Browser Output From Both Methods

Add Header Code Here

Here is some text from the main file.

Add Custom Footer