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:
Posizione del Parametro | Tipo | Obbligatorio | Default | Descrizione |
---|---|---|---|---|
1 | intero | No | 80 | Stabilisce a quanti caratteri effettuare il troncamento. |
2 | stringa | No | ... | Testo da aggiungere in fondo quando c'è troncamento. |
3 | booleano | No | false | Stabilisce se troncare dopo una parola (false), o al carattere esatto (true). |
Effettua il troncamento di una variabile ad un certo numero di caratteri, per default 80. Come secondo parametro opzionale potete specificare una stringa di testo da mostrare alla fine se la variabile è stata troncata. Questi caratteri non vengono conteggiati nella lunghezza della stringa troncata. Per default, truncate cercherà di tagliare la stringa al termine di una parola. Se invece volete effettuare il troncamento alla lunghezza esatta in caratteri, passate il terzo parametro opzionale come true.
Example 5.20. truncate
<?php $smarty = new Smarty; $smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.'); $smarty->display('index.tpl'); ?>
Dove index.tpl è:
{$articleTitle} {$articleTitle|truncate} {$articleTitle|truncate:30} {$articleTitle|truncate:30:""} {$articleTitle|truncate:30:"---"} {$articleTitle|truncate:30:"":true} {$articleTitle|truncate:30:"...":true}
Questo stamperà:
Two Sisters Reunite after Eighteen Years at Checkout Counter. Two Sisters Reunite after Eighteen Years at Checkout Counter. Two Sisters Reunite after... Two Sisters Reunite after Two Sisters Reunite after--- Two Sisters Reunite after Eigh Two Sisters Reunite after E...