LisDesigns  d                  
Home

About Us

Services

Portfolio

Freebies

Tutorials

Chat

Contact Us

Smarty Template Engine

Smarty code is written in curly brace delimiters.
{* Comments are enclosed in curly brace delimiters with an Asterix, like this *}
Variables for templates start with a $dollar sign.
Eg.
<html>
<head>
<title>{$title}
<meta name="keywords" content="{$keyword[1]}">
<meta name="description" content="{$desc.val}">
</head>
Object: {$content->writing();}
Expression: {$total*1.10;}
</html>
Files are included like this:
{config_load file="colors.conf"}
{include file="header.tpl"}
{insert file="banner.tpl" title="Smarty Website"}
- Title is called an attribute.
Php is deprecated but can be included like this:
{php}
include('/path/to/file.php');
{/php}
If else statements are written like this:
{if $day == "Monday"}
Welcome to {$day}!
{else}
Have a rest.
{/if}

Smarty accepts variable strings in double quotes:
{func var="test $foo test"}
{func var="test `$foo.bar` test"}
{func var="test {time()} test"}
<script>
// the following script is ignored by Smarty
function testfoo {
alert('testfoo!');
}
// literal escape means smarty will recognize the function
{literal}
function dizzy {alert('foo foo!');}
{/literal}
//Escape Eg2.
{ldelim}
function {alert('ldelim');}

{/rdelim}

No cache example:
The date today is
{nocache}
{$smarty.now|date_format}
{/nocache}
This is how a variable is assigned a value:
{php}
$this->assign('varFav','Caramel');
{/php}
{* output the variable *}
<b>{$varFav}</b> is my fav falvour. :)

Example 1_php

Example 1_tpl

Output:

smarty example 1 output

While example with checkboxes - php

While example with checkboxes - tpl

Output:

smarty while example output
Click here for a crash course tutorial with examples from Smarty.net.