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:
Nome Attributo | Tipo | Obbligatorio | Default | Descrizione |
---|---|---|---|---|
file | stringa | sì | nessuno | nome/percorso dell'immagine |
border | stringa | no | 0 | dimensione del bordo dell'immagine |
height | stringa | no | altezza effettiva dell'immagine | altezza con cui visualizzare l'immagine |
width | stringa | no | larghezza effettiva dell'immagine | larghezza con cui visualizzare l'immagine |
basedir | stringa | no | doc root del web server | directory di base per percorsi relativi |
alt | stringa | no | "" | descrizione alternativa dell'immagine |
href | stringa | no | nessuno | valore di href per il link dell'immagine |
html_image è una funzione utente che genera un tag HTML per una immagine. L'altezza e la larghezza, quando non indicate, vengono calcolate automaticamente dal file dell'immagine.
basedir è la directory di riferimento per percorsi relativi. Se non viene indicata, viene usata come base la document root del web server (variabile di ambiente DOCUMENT_ROOT). Se la security è abilitata, il percorso dell'immagine deve trovarsi in una directory considerata sicura.
href
è l'indirizzo del link a cui collegare
l'immagine. Se viene fornito, verrà creato un tag
<a href="LINKVALUE"><a> attorno al tag image.
Tutti i parametri non compresi nella lista qui sopra vengono stampati come coppie nome/valore all'interno del tag <img> generato.
html_image richiede un accesso al disco per leggere il file dell'immagine e calcolarne altezza e larghezza. Se non usate il caching dei template, è generalmente consigliabile evitare html_image e lasciare i tag image statici per ottenere prestazioni ottimali.
Example 8.7. esempio di html_image
<?php require('Smarty.class.php'); $smarty = new Smarty; $smarty->display('index.tpl'); ?>
dove index.tpl è:
{html_image file="pumpkin.jpg"} {html_image file="/path/from/docroot/pumpkin.jpg"} {html_image file="../path/relative/to/currdir/pumpkin.jpg"}
un possibile output potrebbe essere:
<img src="pumpkin.jpg" alt="" border="0" width="44" height="68" /> <img src="/path/from/docroot/pumpkin.jpg" alt="" border="0" width="44" height="68" /> <img src="../path/relative/to/currdir/pumpkin.jpg" alt="" border="0" width="44" height="68" />