(redirected from Main.UsingSmarty)
Using Smarty is where things start to get complicated. Smarty uses a special templating language which is supposed easier than using PHP directly. There is some controversy about this.
If you do choose to use Smarty, you will need to develop templates for each of your views. Templating structure is fairly straight-forward as well. Best practice is to make your templates as structured and modular as possible. Thus, you may have the following in your main template:
{include file="header.tpl"}
{insert file="banner_ads.tpl" title="My Site"}
{if $logged_in}
Welcome, <span style="color:{#fontColor#}">{$name}!</span>
{else}
hi, {$name}
{/if}
{include file="footer.tpl"}
Here we see some conventions:
- Smarty syntax is fairly straight-forward.
- There is a PHP-like language (in fact, it is PHP with some restrictions)
- There are built-in functions for doing various things
- There are variables that can be set and passed to Smarty
To execute the template, you make the various assignments to pass variables to Smarty, then you display the template:
$smarty->display('main.tpl');
In Smarty template files, you mix the Smarty code with HTML, as you would if you were using PHP directly for display.
See The Smarty Documentation for details on writing Smarty templates.
<< Back to Configuring Smarty
| Tags: | Categories: Articles |
Recent Changes |
Printable View |
Page History |
Edit Page
Page last modified on April 13, 2012, at 01:56 PM by tamara