Plugins für smarty
Hier stelle ich einige Plugins für Smarty aus.
Diese gehören in den smartyPlugins-Ordner Eurer lokalen Smarty-Installation. Danach könnt Ihr sie wie gemeine modifier nutzen, also zB
Anwendung in der template
{$size|gbSize}
im template sagen, dann wird automatisch formatiert. Wie immer.
gemeinize
/*
* Smarty plugin
* -------------------------------------------------------------
* File: modifier.gemeinize.php
* Type: modifier
* Name: gemeinize
* Purpose: be an antagonist to capitalize
* -------------------------------------------------------------
*/
function smarty_modifier_gemeinize($string) {
$tmp = substr($string,0,1);
return strtolower($tmp) . substr($string,1);
}
Verkleinert den ersten Buchstaben von string.
gbSize
/*
* Smarty plugin
* -------------------------------------------------------------
* File: modifier.gbSize.php
* Type: modifier
* Name: gbSize
* Purpose: format sizes to SI units
* -------------------------------------------------------------
*/
function smarty_modifier_gbSize($numba, $digits = 2) {
$sizes = array("Tebi Bytes", "Gibi Bytes", "Mebi Bytes", "Kibi Bytes", "Bytes");
$total = count($sizes);
while ($total-- && $numba > 1024) {
$numba /= 1024;
}
return round($numba, $digits) . " " . $sizes[$total];
}
Formatiert bytes nach SI-Einheiten.