Scriptindex.de

[ Menü ]

Home
News
Scripts
Neuzugänge
Suchen
Bücher
Manuals

[ Inhalt ]

Script eintragen
Tutorial eintragen
Newsletter
Umfragen
Link zu uns
Werbung bei uns
Kontakt
Impressum

[ Statistik ]

Hits gesamt: 5204161
Hits Heute: 818
max. Hits (10.07.07): 6964
User Online: 42
Scripts: 2828

[ Partner ]

CodeBase
I.S.U.M.
LUG Bayreuth
PEAR NEWS
PHP Classes

[ Facebook ]

[ Eigene Domain? ]

[ Buchtipp ]

XML im Unternehmen. Briefing fürs IT- Management.
XML im Unternehmen. Briefing fürs IT- Management.

Manuals > Smarty > Variablen-Modifikatoren

16.5. Variablen-Modifikatoren

Variablen-Modifikatoren sind kleine Funktionen, die auf eine Variable angewendet werden, bevor sie ausgegeben oder weiterverwendet wird. Variablen-Modifikatoren können aneinadergereiht werden.

mixed smarty_modifier_name(mixed $value, [mixed $param1, ...]);

Der erste an das Modifikator-Plugin übergebene Parameter ist der Wert mit welchem er arbeiten soll. Die restlichen Parameter sind optional und hängen von den durchzuführenden Operationen ab.

Der Modifikator muss das Resultat seiner Verarbeitung zurückgeben.

Sehen Sie dazu: register_modifier(), unregister_modifier().

Beispiel 16-3. Einfaches Modifikator-Plugin

Dieses Plugin dient als Alias einer PHP-Funktion und erwartet keine zusätzlichen Parameter.

<?php /* * Smarty plugin * ------------------------------------------------------------- * File: modifier.capitalize.php * Type: modifier * Name: capitalize * Purpose: capitalize words in the string * ------------------------------------------------------------- */ function smarty_modifier_capitalize($string) { return ucwords($string); } ?>

Beispiel 16-4. Komplexes Modifikator-Plugin

<?php /* * Smarty plugin * ------------------------------------------------------------- * File: modifier.truncate.php * Type: modifier * Name: truncate * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string. * ------------------------------------------------------------- */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false) { if ($length == 0) return ''; if (strlen($string) > $length) { $length -= strlen($etc); $fragment = substr($string, 0, $length+1); if ($break_words) $fragment = substr($fragment, 0, -1); else $fragment = preg_replace('/\s+(\S+)?$/', '', $fragment); return $fragment.$etc; } else return $string; } ?>

Copyright 1998 - 2009 by I.S.U.M.