Smarty poziada kilka róznych typów zmiennych. Typ zmiennej zalezy od tego jakim znakiem jest ona zaczeta i jakim znakiem jest zakończona.
Zmienne Smarty moga być bezpośrednio wyświetlone lub uzyte jako argumenty dla atrybutów funkcji i modyfikatorów, wewnątrz instrukcji warunkowych itd. Aby wyświetlić zmienną popostu zamkni ją ogranicznikiem tak iż bedzie ona tylko w ogranicznikach.
Zmienne przyporządkowane z PHP są rozpoznawane przez poprzedzanie ich znakiem dolara $. Zmienne przyporządkowane z wewnątrz szablonu przez funkcje assign również wyglądają w ten sposób.
Możesz również odwoływać się do tablic asocjacyjnych przyporządkowanych z PHP poprzez podanie klucza po symbolu '.' (kropka).
Example 3.11. Odwoływanie się do zmiennych w tablicy asocjacyjnej
index.php:
$smarty = new Smarty;
$smarty->assign('Contacts',
array('fax' => '555-222-9876',
'email' => 'zaphod@slartibartfast.com',
'phone' => array('home' => '555-444-3333',
'cell' => '555-111-1234')));
$smarty->display('index.tpl');
index.tpl:
{$Contacts.fax}<br>
{$Contacts.email}<br>
{* możesz również wyświetlac tablice zawartą w tablicy *}
{$Contacts.phone.home}<br>
{$Contacts.phone.cell}<br>
OUTPUT:
555-222-9876<br>
zaphod@slartibartfast.com<br>
555-444-3333<br>
555-111-1234<br>Możesz odwoływać się do tablic przez ich indeks, tak samo jak w PHP.
Example 3.12. Odwoływanie się do tablic przez index
index.php:
$smarty = new Smarty;
$smarty->assign('Contacts',
array('555-222-9876',
'zaphod@slartibartfast.com',
array('555-444-3333',
'555-111-1234')));
$smarty->display('index.tpl');
index.tpl:
{$Contacts[0]}<br>
{$Contacts[1]}<br>
{* możesz również wyświetlac tablice zawartą w tablicy *}
{$Contacts[2][0]}<br>
{$Contacts[2][1]}<br>
OUTPUT:
555-222-9876<br>
zaphod@slartibartfast.com<br>
555-444-3333<br>
555-111-1234<br>Do własności obiektów przyporządkowanych z PHP można się odwoływać podając nazwę własności po symbolu '->'.
Do zmiennych ładowanych z plików konfiguracyjnych można się odwoływać przez zamknięcie ich w znaki hasch (#), albo ze zmiennej Smarty $smarty.config. Drugi sposób jest użyteczny przy osadzaniu w cytowanych wartościach atrybutów.
Example 3.14. Zmienne konfiguracyjne
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: (alternate syntax)
{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>
OUTPUT: (same for both examples)
<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>mienne pliku konfiguracyjnego nie mogą być używane dopóki nie zostaną załadowane z pliku konfiguracyjnego. Ta procedura zostanie wyjaśniona później podczas omawiania {config_load}.
Ta zarezerwowana zmienna {$smarty} może być użyta do dostępu do kilku specjalnych zmiennych szablonu.
Do zmiennych Request takie jak get, post, server, enviroment i session można uzyskać dostęp tak jak na przykładzie poniżej.
Example 3.15. Wyświetlanie zmiennych typu Request
{* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *}
{$smarty.get.page}
{* display the variable "page" from a form a form (POST) *}
{$smarty.post.page}
{* display the value of the cookie "username" *}
{$smarty.cookies.username}
{* display the server variable "SERVER_NAME" *}
{$smarty.server.SERVER_NAME}
{* display the system environment variable "PATH" *}
{$smarty.env.PATH}
{* display the php session variable "id" *}
{$smarty.session.id}
{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username}Dostęp do czasu w danej chwili może być możliwy z {$smarty.now}. Numer ten przedstawia liczbę sekund od 1 stycznia 1970 i może być skierowany do modyfikatora date_format aby wyświetlić go w odpowiedniej formie.
Możesz uzyskać dostęp do stałych z PHP.
Do wyjścia przechwyconego przez {capture}..{/capture} można uzyskać dostęp przez zmienną {$smarty.capture}.
Zmienna {$smarty} może być używana do kierowania do zmiennych konfiguracyjnych. {$smarty.config.foo} jest synonimem dla {#foo#}.
Zmienna {$smarty} może być używana do sterowania pętlami 'section' i 'foreach' .
Modyfikatory zmiennych mogą być stosowane do zmiennych, zdefiniowanych funkcji albo ciągów znaków. Aby zastosować modyfikator, podaj ziemną za którą umieść znak | (pipe) i potem nazwę modyfikatora. Modyfikator może akceptować dodatkowe parametry określające jego zachowanie. Te parametry podaje się za nazwą modyfikatora i oddzielając je przez znak : (dwukropek)
Example 3.18. Przykład modyfikatorów
{* Uppercase the title *}
<h2>{$title|upper}</h2>
{* Truncate the topic to 40 characters use ... at the end *}
Topic: {$topic|truncate:40:"..."}
{* format a literal string *}
{"now"|date_format:"%Y/%m/%d"}
{* apply modifier to a custom function *}
{mailto|upper address="me@domain.dom"}Jeśli zastosujesz modyfikator do tablicy, modyfikator zostanie zastosowany do każdego elementu tablicy. Jeśli chcesz aby modyfikator pracował na tablicy (całej jako jednej zmiennej) musisz poprzedzić nazwę modyfikatora symbolem @ np {$articleTitle|@count}(to wyświetli liczbę elementów w tablicy $articleTitle)
Służy do zmieniania pierwszej litery każdego słowa w zmiennej na dużą.
Example 3.19. capitalize
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'Police begin campaign to rundown jaywalkers.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|capitalize}
OUTPUT:
Police begin campaign to rundown jaywalkers.
Police Begin Campaign To Rundown Jaywalkers.Używany jest do liczenia liczby znaków w zmiennej.
Ten modyfikator służy dodawaniu ciągu znaków na końcu zmiennej.
| Pozycja parametru | Typ | Wymagany | cat | Opis |
|---|---|---|---|---|
| 1 | string | nie | pusty | Wartośc która zostanie dodana do podanej zmiennej. |
Zlicza ilość znaków w podanej zmiennej.
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | boolean | nie | false | Decyduje o tym czy spacje wliczane są do całkowitej liczby znaków. |
Zlicza liczbę akapitów w zmiennej.
Example 3.23. count_paragraphs
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'War Dims Hope for Peace. Child's Death Ruins Couple's Holiday.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|count_paragraphs}
OUTPUT:
War Dims Hope for Peace. Child's Death Ruins Couple's Holiday.
Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation.
2Zlicza ilość zdań w zmiennej.
Example 3.24. count_sentences
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|count_sentences}
OUTPUT:
Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.
2Zlicza ilość wyrazów w zmiennej.
Formatuje datę i czas do danego według podanego formatu strftime() . Data może zostać przekazana do Smarty jako uniksowe timestamps, mysql timestamps lub przez dowolny ciąg znaków złożony z miesiąca dnia roku (możliwego do sparsowania przez strtotime()). Projektanci mogą używać date_format do zachowania kontroli nad formatowaniem daty. Jeśli data przekazana do date_format jest pusta i drugi parametr jest podany, zostanie on uzyty jako data do sformatowania.
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | string | nie | %b %e, %Y | Format wyjściowy daty. |
| 2 | string | nie | brak | Domyślna data, jesli data wejściowa jest pusta. |
Od Smarty-2.6.10 wszystkie wartosci numeryczne ( z wyjatkiem mysql timestamps) przekazywane do date_format zawsze będą interpretowane jako unix timestamp.
Example 3.26. date_format
index.php:
$smarty = new Smarty;
$smarty->assign('yesterday', strtotime('-1 day'));
$smarty->display('index.tpl');
index.tpl:
{$smarty.now|date_format}
{$smarty.now|date_format:"%A, %B %e, %Y"}
{$smarty.now|date_format:"%H:%M:%S"}
{$yesterday|date_format}
{$yesterday|date_format:"%A, %B %e, %Y"}
{$yesterday|date_format:"%H:%M:%S"}
OUTPUT:
Feb 6, 2001
Tuesday, February 6, 2001
14:33:00
Feb 5, 2001
Monday, February 5, 2001
14:33:00Example 3.27. ddane konwersji datydate_format
%a - abbreviated weekday name according to the current locale
%A - full weekday name according to the current locale
%b - abbreviated month name according to the current locale
%B - full month name according to the current locale
%c - preferred date and time representation for the current locale
%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
%d - day of the month as a decimal number (range 00 to 31)
%D - same as %m/%d/%y
%e - day of the month as a decimal number, a single digit is preceded by a space (range 1 to 31)
%g - Week-based year within century [00,99]
%G - Week-based year, including the century [0000,9999]
%h - same as %b
%H - hour as a decimal number using a 24-hour clock (range 00 to 23)
%I - hour as a decimal number using a 12-hour clock (range 01 to 12)
%j - day of the year as a decimal number (range 001 to 366)
%k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
%l - hour as a decimal number using a 12-hour clock, single digits preceeded by a space (range 1 to 12)
%m - month as a decimal number (range 01 to 12)
%M - minute as a decimal number
%n - newline character
%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale
%r - time in a.m. and p.m. notation
%R - time in 24 hour notation
%S - second as a decimal number
%t - tab character
%T - current time, equal to %H:%M:%S
%u - weekday as a decimal number [1,7], with 1 representing Monday
%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
%V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
%w - day of the week as a decimal, Sunday being 0
%W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
%x - preferred date representation for the current locale without the time
%X - preferred time representation for the current locale without the date
%y - year as a decimal number without a century (range 00 to 99)
%Y - year as a decimal number including the century
%Z - time zone or name or abbreviation
%% - a literal `%' character
Jest używany do nadania zmiennej wartości domyślnej. Jeśli zmienna jest pusta lub nie zdefiniowana wyświetlana jest wartość domyślna. Default wymaga jednego argumentu.
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | string | nie | pusty | Domyślna wartość wyjścia jeżeli zmienna jest pusta. |
Używany jest do html escape, url escape, escape single quotes on a variable not already escaped, hex escape, hexentity or javascript escape. Domyślnie, modyfikator przyjmuje argument html . ???????
| Pozycja parametru | Typ | Wymagany | Mozliwe wartości | Domyślnie | Opis |
|---|---|---|---|---|---|
| 1 | string | nie | html, htmlall, url, quotes, hex, hexentity, javascript | html | Jakiego typu "eskejpowanie" znaków zostanie zastosowane. |
Example 3.29. escape
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', "'Stiff Opposition Expected to Casketless Funeral Plan'");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|escape}
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
{$articleTitle|escape:"htmlall"} {* escapes ALL html entities *}
{$articleTitle|escape:"url"}
{$articleTitle|escape:"quotes"}
<a
href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
OUTPUT:
'Stiff Opposition Expected to Casketless Funeral Plan'
'Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan'
'Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan'
'Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan'
'Stiff+Opposition+Expected+to+Casketless+Funeral+Plan'
\'Stiff Opposition Expected to Casketless Funeral Plan\'
<a
href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">bob@me.net</a>Wcina ciąg znaków w każdej lini, domyślna wartość to 4. Jako opcjonalny drugi argument, możesz podać parametr jakim będzie się posługiwał modyfikator aby stworzyć wycięcie. (Używaj "\t" dla tabulacji.)
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | integer | nie | 4 | Decyduje o tym ile znaków bedzie posiadało wciecie |
| 2 | string | nie | jedna spacja | Znak używany do stworzenia wciecia. |
Example 3.30. ident
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'NJ judge to rule on nude beach.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|indent}
{$articleTitle|indent:10}
{$articleTitle|indent:1:"\t"}
OUTPUT:
NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.
NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.
NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.
NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.Jest używany do zmiany wszystkich liter na małe.
W podanej zmiennej wszystkie łamania linii (entery) będą przekształcone do znaczników <br />. Jest to ekwiwalent funkcji PHP - nl2br().
Wyrażenie regularne przeszukujące i zamieniające w zmiennej. Używaj wyrażeń dla preg_replace() z manuala PHP.
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | string | tak | brak | Wyrażenie regularne które będzie zastąpione. |
| 2 | string | tak | brak | Tekst do wstawienia w miejsce znalezionych wyrażeń. |
Example 3.33. regex_replace
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
$smarty->display('index.tpl');
index.tpl:
{* replace each carriage return, tab & new line with a space *}
{$articleTitle}
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
OUTPUT:
Infertility unlikely to
be passed on, experts say.
Infertility unlikely to be passed on, experts say.Proste szukanie i zamiana w zmiennej.
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | string | tak | brak | Ciągi znaków które będą zastąpione. |
| 2 | string | tak | brak | Tekst do wstawienia w miejsce znalezionych ciągów. |
Example 3.34. replace
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|replace:"Garden":"Vineyard"}
{$articleTitle|replace:" ":" "}
OUTPUT:
Child's Stool Great for Use in Garden.
Child's Stool Great for Use in Vineyard.
Child's Stool Great for Use in Garden.spacify umożliwia wstawienie spacji pomiędzy każdym znakiem w zmiennej. Możesz opcjonalnie podać inny znak (lub ciąg znaków) do wstawienia.
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | string | nie | jedna spacja | Ten parametr będzie umieszczony pomiędzy każda parą znaków. |
Example 3.35. spacify
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|spacify}
{$articleTitle|spacify:"^^"}
OUTPUT:
Something Went Wrong in Jet Crash, Experts Say.
S o m e t h i n g W e n t W r o n g i n J e t C r a s h , E x p e r t s S a y .
S^^o^^m^^e^^t^^h^^i^^n^^g^^ ^^W^^e^^n^^t^^ ^^W^^r^^o^^n^^g^^ ^^i^^n^^ ^^J^^e^^t^^ ^^C^^r^^a^^s^^h^^,^^ ^^E^^x^^p^^e^^r^^t^^s^^ ^^S^^a^^y^^.Umożliwia formatowanie ciągów znaków takich jak ułamki dziesiętne i podobnych. Do formatowania używaj wyrażeń do sprintf .
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | string | tak | jedna spacja | Format tekstu (sprintf) |
Zastępuje wszystkie powtarzające się spacje, łamanie linii i tabulatory pojedynczą spacją, albo podanym ciągiem znaków .
Jeżeli chcesz użyć tego modyfikatora stosunku do bloków tekstu w szablonie, użyj strip function.
Example 3.37. strip
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|strip}
{$articleTitle|strip:" "}
OUTPUT:
Grandmother of
eight makes hole in one.
Grandmother of eight makes hole in one.
Grandmother of eight makes hole in one.Wycina i oznacza tekst z pomiędzy znaczników, domyślnie spomiędzy < i >.
Example 3.38. strip_tags
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', "Blind Woman Gets <font face=\"helvetica\">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|strip_tags}
OUTPUT:
Blind Woman Gets <font face="helvetica">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.
Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.Obcina zmienną do podanej długości (domyślnie do 80 znaków). Jako opcjonalny drugi parametr możesz podać ciąg znaków wyświetlanych na końcu obciętej zmiennej. Znaki w podanym ciągu znaków są wliczone do oryginalnej długości przycinania. Domyślnie, obcięcie następuje przy końcu ostatniego słowa. Jeśli chcesz przyciąć dokładnie do takiej długości jaką podałeś podaj opcjonalny trzeci parametr jako true (prawda).
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | integer | nie | 80 | Decyduje ile ciąg może mieć znaków. |
| 2 | string | nie | ... | Tekst do wstawienia na końcu wyswietlonego obcietego textu. |
| 3 | boolean | nie | fałsz | Decydujeo tym czy pzepuścic ostatni wyraz czy obcinac tekst dokładnie do podanej liczby znaków. |
Example 3.39. truncate
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
OUTPUT:
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...Używany jest do zwiększenia wszystkich liter w zmiennej na duże.
Example 3.40. upper
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|upper}
OUTPUT:
If Strike isn't Settled Quickly it may Last a While.
IF STRIKE ISN'T SETTLED QUICKLY IT MAY Pakuje zmienną do kolumny, domyślna szerokość kolumny to 80. Jako opcjonalny drugi parametr, możesz podać ciąg znaków który będzie przenosił tekst do nowej linii (domyślnie jest to return \n). Domyślnie przenoszenie do nowej linii na końcu ostatniego wyrazu mieszczącego się w linii. Jeśli chcesz przyciąć dokładnie do takiej długości jaką podałeś podaj opcjonalny trzeci parametr jako true (prawda).
| Pozycja parametru | Typ | Wymagany | Domyślnie | Opis |
|---|---|---|---|---|
| 1 | integer | nie | 80 | Decyduje co ile znaków wstawiać zdefiniowany tekst. |
| 2 | string | nie | \n | Tekst do wstawienia co okreslona ilośc znaków. |
| 3 | boolean | nie | fałsz | Decydujeo tym czy przepuścić ostatni wyraz czy wstawić znak dokładnie po podanej liczby znaków. |
Example 3.41. wordwrap
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', "Blind woman gets new kidney from dad she hasn't seen in years.");
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|wordwrap:30}
{$articleTitle|wordwrap:20}
{$articleTitle|wordwrap:30:"<br>\n"}
{$articleTitle|wordwrap:30:"\n":true}
OUTPUT:
Blind woman gets new kidney from dad she hasn't seen in years.
Blind woman gets new kidney
from dad she hasn't seen in
years.
Blind woman gets new
kidney from dad she
hasn't seen in
years.
Blind woman gets new kidney<br>
from dad she hasn't seen in years.
Blind woman gets new kidney fr
om dad she hasn't seen in year
s.Możesz zastosować dowolna liczbę modyfikatorów do zmiennej. Będą wykonywane w kolejności w jakiej zostały wywołane (z lewej na prawą). Muszą być oddzielone znakiem | (pipe).
Example 3.42. mieszanie modyfikatorów
index.php:
$smarty = new Smarty;
$smarty->assign('articleTitle', 'Smokers are Productive, but Death Cuts Efficiency.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|upper|spacify}
{$articleTitle|lower|spacify|truncate}
{$articleTitle|lower|truncate:30|spacify}
{$articleTitle|lower|spacify|truncate:30:". . ."}
OUTPUT:
Smokers are Productive, but Death Cuts Efficiency.
S M O K E R S A R E P R O D U C T I V E , B U T D E A T H C U T S E F F I C I E N C Y .
s m o k e r s a r e p r o d u c t i v e , b u t d e a t h c u t s...
s m o k e r s a r e p r o d u c t i v e , b u t . . .
s m o k e r s a r e p. . .
s.