Simple manipulations
value; ?>
method(); ?>
Many other combinations are allowed
methodArgs($tpl["baz_key"], 2, 2.3, "some string", $tpl["bar_key"]); ?> <-- passing parameters
Math and embedding tags:
// will output the sum of x and y.
// tags within tags
// tags within double quoted strings
Short variable assignment:
// function in assignment
// as function parameter
// assign to specific array element
Smarty "dot" syntax (note: embedded {} are used to address ambiguities):
Object chaining:
getSelf($tpl["x"])->method($tpl["y"]); ?>
Direct PHP function access:
'.$tpl["name"].'';
} else {
echo "hi, ".$tpl["user"]["name"];
}
?>
Embedding Vars in Double Quotes
$tpl["user"]["email"],"text" => "test ".$tpl["item"]." test"), $tpl).
MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".$tpl["foo_key"]." test"), $tpl).
MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".($tpl["data"][4])." test"), $tpl).
MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".$tpl["item"].".bar test"), $tpl).
MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => 'test {$data.barz} test'), $tpl).
MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".($tpl["data"]["barz"])." test"), $tpl).
MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => strtoupper("test ".($tpl["data"]["barz"])." test")), $tpl).
MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".(strtoupper($tpl["data"]["barz"]))." test"), $tpl); ?>
will replace $tpl_name with value
does NOT replace $tpl_name
$tpl["user"]["email"],"text" => "one,two"), $tpl); ?>
Math
some more complicated examples
num * !$tpl["data"]["foo"]["baz"]["ls"][4] - 3 * 7 % $tpl["data"][2]; ?>
num * $tpl["data"]["foo"]["baz"]["ls"][4] - 3 * 7 % $tpl["data"][2]) {
echo MF\Misc\Str::truncate($tpl["data"]["barz"], "".($tpl["data"][2] / 2 - 1)."")."\n".
MF\Misc\Str::truncate($tpl["data"]["barz"], ($tpl["data"][2] / 2 - 1));
}
?>
Escaping Smarty Parsing
name:
email:
Modifier examples
apply modifier to a variable
modifier with parameters
apply modifier to a function parameter
$tpl["user"]["email"],"text" => strtoupper($tpl["user"]["name"])), $tpl); ?>
with parameters
$tpl["user"]["email"],"text" => MF\Misc\Str::truncate($tpl["user"]["name"], 40, "...")), $tpl); ?>
apply modifier to literal string
using date_format to format the current date
apply modifier to a custom function
Foreach
$tpl["value"]) {
echo $tpl["key"].": ".$tpl["value"]." ";
}
} else {
echo "no items";
}
}
}
?>
If condition
0) {
echo "do a foreach loop";
}
?>