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:
Smarty has several different types of variables. The type of the variable depends on what symbol it is prefixed or enclosed within.
Variables in Smarty can be either displayed directly or used as arguments for functions, attributes and modifiers, inside conditional expressions, etc. To print a variable, simply enclose it in the delimiters so that it is the only thing contained between them.
Top Tip: An easy way to examine Smarty variables is with the debugging console.
Variabel assigned dari PHP direferensi oleh pendahulunya dengan tanda dolar $ (seperti php). Variabel yang ditempati dari dalam template dengan fungsi {assign} juga ditampilkan dengan cara ini.
Anda juga bisa mereferensi variabel array asosiatif yang ditempatkan dari PHP dengan menetapkan kunci setelah simbol '.' (titik).
Teladan 4-3. Mengakses variabel array asosiatif
di mana konten index.tpl adalah:
ini akan menampilkan:
|
Anda bisa mereferensi array dengan indeksnya, lebih mirip dengan sintaks PHP.
Teladan 4-4. Mengakses array dengan indeks
di mana index.tpl adalah:
Ini akan menampilkan:
|
Properti obyek yang ditempatkan dari PHP dapat direferensi dengan menetapkan nama properti setelah simbol ->.