What is Smarty?
Why use it?
Use Cases and Work Flow
Syntax Comparison
Template Inheritance
Best Practices
Crash Course
You may use the Smarty logo according to the trademark notice.
For sponsorship, advertising, news or other inquiries, contact us at:
Variable modifiers can be applied to variables, custom functions or strings. To apply a modifier, specify the value followed by a | (pipe) and the modifier name. A modifier may accept additional parameters that affect its behavior. These parameters follow the modifer name and are separated by a : (colon). Also, all php-functions can be used as modifiers implicitly (more below) and modifiers can be combined. .
If you apply a modifier to an array variable instead of a single value variable, the modifier will be applied to every value in that array. If you really want the modifier to work on an entire array as a value, you must prepend the modifier name with a @ symbol.
Example: {$articleTitle|@count} - will print out the number of elements in the $articleTitle array using the php count() function as a modifier.
Modifiers are autoloaded from the $plugins_dir or can be registered explicitly with the register_modifier() function. The later is useful for sharing a function between php scripts and smarty templates.
All php-functions can be used as modifiers implicitly, as demonstrated in the example above. However, using php-functions as modifiers has two little pitfalls:
First - sometimes the order of the function-parameters is not the desirable one. Formatting $foo with {"%2.f"|sprintf:$foo} actually works, but asks for the more intuitive, like {$foo|string_format:"%2.f"} that is provided by the Smarty distribution.
Secondly - if $security is enabled, all php-functions that are to be used as modifiers have to be declared trusted in the MODIFIER_FUNCS element of the $security_settings array.
See also register_modifier(), combining modifiers. and extending smarty with plugins
Ini dipakai untuk membesarkan huruf pertama dari seluruh kata dalam variable. Mirip dengan fungsi PHP ucfirst().
Posisi Parameter | Tipe | Diperlukan | Default | Deskripsi |
---|---|---|---|---|
1 | boolean | Tidak | FALSE | Ini menentukan apakah kata dengan digit akan dibesarkan atau tidak |
Teladan 5-2. capitalize
Di mana template adalah:
Akan memperlihatkan:
|