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:
Le variabili caricate dai file di configurazione sono referenziate racchiudendole fra due simboli cancelletto (#), oppure attraverso la variabile $smarty.config. La seconda sintassi è utile per includerle in valori di attributi indicati fra virgolette.
Example 4.5. variabili di configurazione
foo.conf:
pageTitle = "This is mine" bodyBgColor = "#eeeeee" tableBorderSize = "3" tableBgColor = "#bbbbbb" rowBgColor = "#cccccc"
index.tpl:
{config_load file="foo.conf"} <html> <title>{#pageTitle#}</title> <body bgcolor="{#bodyBgColor#}"> <table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}"> <tr bgcolor="{#rowBgColor#}"> <td>First</td> <td>Last</td> <td>Address</td> </tr> </table> </body> </html>
index.tpl: (sintassi alternativa)
{config_load file="foo.conf"} <html> <title>{$smarty.config.pageTitle}</title> <body bgcolor="{$smarty.config.bodyBgColor}"> <table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}"> <tr bgcolor="{$smarty.config.rowBgColor}"> <td>First</td> <td>Last</td> <td>Address</td> </tr> </table> </body> </html>
questo è l'output prodotto da entrambi gli esempi:
<html> <title>This is mine</title> <body bgcolor="#eeeeee"> <table border="3" bgcolor="#bbbbbb"> <tr bgcolor="#cccccc"> <td>First</td> <td>Last</td> <td>Address</td> </tr> </table> </body> </html>
Le variabili dei file di configurazione non possono essere usate fino a dopo che sono state caricate dal file che le contiene. Questa procedura viene spiegata più avanti in questo documento, in config_load.