| 1 | <h2>Comments</h2> |
| 2 | <pre><code>{* This is a comment with <p>some markup</p> in it *} |
| 3 | {* Multi-line |
| 4 | comment *}</code></pre> |
| 5 | |
| 6 | <h2>Variables</h2> |
| 7 | <pre><code>{$foo} |
| 8 | {$foo.bar} |
| 9 | {$foo.$bar} |
| 10 | {$foo[$bar]} |
| 11 | {$foo->bar} |
| 12 | {$foo->bar()} |
| 13 | {#foo#} |
| 14 | {$smarty.config.foo} |
| 15 | {$foo[bar]} |
| 16 | </code></pre> |
| 17 | |
| 18 | <h2>Strings and numbers</h2> |
| 19 | <pre><code>{$foo[4]} |
| 20 | {$foo['bar']}</code></pre> |
| 21 | |
| 22 | <h2>Tags and filters</h2> |
| 23 | <pre><code>{assign var=foo value='baa'} |
| 24 | {include file='header.tpl'} |
| 25 | {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'} |
| 26 | {$title|truncate:40:'...'} |
| 27 | {$myArray|@count} |
| 28 | |
| 29 | {math equation="height * width / division" |
| 30 | height=$row_height |
| 31 | width=$row_width |
| 32 | division=#col_div#}</code></pre> |
| 33 | |
| 34 | <h2>Control flow</h2> |
| 35 | |
| 36 | <pre><code>{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#} |
| 37 | ... |
| 38 | {/if} |
| 39 | {if count($var) gt 0}{/if} |
| 40 | {if $var is even by 3} |
| 41 | ... |
| 42 | {/if} |
| 43 | |
| 44 | {foreach from=$myArray item=i name=foo} |
| 45 | {$smarty.foreach.foo.index}|{$smarty.foreach.foo.iteration}, |
| 46 | {/foreach} |
| 47 | |
| 48 | <ul> |
| 49 | {foreach from=$items key=myId item=i} |
| 50 | <li><a href="item.php?id={$myId}">{$i.no}: {$i.label}</li> |
| 51 | {/foreach} |
| 52 | </ul> |
| 53 | </code></pre> |
| 54 | |
| 55 | <h2>Literal section</h2> |
| 56 | <pre><code>{literal} |
| 57 | <script> |
| 58 | (function() { /* This is JS, not Smarty */ } ()); |
| 59 | </script> |
| 60 | {/literal} |
| 61 | |
| 62 | <style type="text/css"> |
| 63 | {literal} |
| 64 | /* this is an intersting idea for this section */ |
| 65 | .madIdea{ |
| 66 | border: 3px outset #ffffff; |
| 67 | margin: 2 3 4 5px; |
| 68 | background-color: #001122; |
| 69 | } |
| 70 | {/literal} |
| 71 | </style></code></pre> |