Balupton's jQuery Smarty Plugin (jQSmarty) v{$build}

Download

Home Page

Project Page

Support Page

Source Code

 
Assign:
Code:
{assign var="test" value="works"} {$test}
{assign var="testnum" value=1} {$testnum}
{assign var="test2" value="[]"} {assign var="test2.testa" value="yay"} {assign var="test2.testz" value="!"} {$test2.testa}{$test2.testz}
{$test|default:"Couldn't find $test"}
{$something_that_does_not_exist|default:"Couldn't find $something_that_does_not_exist"}
Result:
Modifiers:
Code:
{"good"|cat:"bye"}
{assign var="test" value="works"|cat:"yay"} {$test}
{"We have five words here"|count_words}
{"hello how are you today?"|capitalize}
Result:
Includes:
Code:
{include file='include.tpl'}
Result:
Loops:
Code:
{section name=customer loop=$custids}

id: {$custids[customer]}
name: {$names[customer]}
address: {$addresses[customer]}

{/section}
Result:
Loops (foreach):
Code:
{foreach from=$tuples key=theKey item=theItem name=theForeach} {cycle values='odd,even' assign='class'} {if $smarty.foreach.theForeach.first} {assign var='class' value=$class|cat:' first'} {elseif $smarty.foreach.theForeach.last} {assign var='class' value=$class|cat:' last'} {/if}

{$smarty.foreach.theForeach.index}|{$smarty.foreach.theForeach.iteration} : {$theItem.custid}, {$theItem.name}, {$theItem.address}

{/foreach}
Result:
Dates:
Code:
{$now|date_format}
{$now|date_format:"%D"}
{$now|date_format:$date}
{$yesterday|date_format}
{$yesterday|date_format:"%A, %B %e, %Y"}
{$yesterday|date_format:$time}
Result:
Logic:
Code:
{assign var="name" value="Wilma"} {$name}
{assign var="amount" value="-1"} {$amount}
{assign var="num" value="55"} {$num}
{assign var="foo" value="[]"} {$foo}

{if $name eq 'Fred'} Welcome Sir. {elseif $name eq 'Wilma'} Welcome Ma'am. {else} Welcome, Unkown. {/if}
{* an example with "or" logic *} {if $name eq 'Fred' or $name eq 'Wilma'} name is fred or wilma {/if}
{* same as above *} {if $name == 'Fred' || $name == 'Wilma'} name is Fred or Wilma {/if}
{* parenthesis are allowed *} {if ( $amount lt 0 or $amount gt 1000 ) } amount is less than 0 or above 1000 {/if}
{* you can also embed php function calls *} {if count($name) gt 0} count of name is above 0 {/if}
{* check for array. *} {if is_array($foo) } foo is an array {/if}
{* check for not null. *} {if isset($foo) } foo is set {/if}
{* test if values are even or odd *} {if $num is even} num is even {/if}
{if $num is odd} num is odd {/if}
{if $num is not odd} num is not odd (even) {/if}
{* test if var is divisible by 4 *} {if $num is div by 4} num is divisible by 4 {/if}
{* test if var is even, grouped by two. i.e., 0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *} {if $num is even by 2} num is even by 2 {/if}
{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *} {if $num is even by 3} num is even by 3 {/if}
Result:
Misc:
Code:
literal
{literal} {include file='include.tpl'} {/literal}

fsize_format
{assign var="filesize" value=773741824} {$filesize|fsize_format:"GB"}
{$filesize|fsize_format}

multiple modifiers:
{"multiple"|cat:" modifiers"|count_words}

onchange:
Change the page title

auto_update:
{$title|default:"No title, so expect the rest to be blank as well..."|capitalize|auto_update}
{$title|capitalize|auto_update::"div":"auto_update"}
{$title|capitalize|auto_update:"title_span"}
{$title|capitalize|auto_update:"div.content.smarty > span.auto_update_manual"}

Result:
Sandbox (things that are still being worked on):
Code:
aaa:
aaa

Result:
ROAD MAP:
TODO:
Add the other functions and modifiers.
Add fetch function.
Improve section function.
DONE:
Added support for: debug, cycle, foreach, ifs, sections, includes, cache, modifiers, functions, assigns.