Hallo,
ich benötige im TPL eine einfache Sortierfunktion - habe diese also als Smarty Plugin gepackt und im Ordner core/smarty/plugins als function.uasort.php gespeichert.
Muss ich nun das Plugin irgendwie registrieren?
Leider kommt nämlich eine Fehlermeldung: … [plugin] modifier ‘sortby’ is not implemented (core.load_plugins.php, line 118) in E:\Apache2\htdocs …
Hat jemand eine Ahnung?
Danke und VG
Stephan
das plugin: function.sortby.php
<?php
sorts an array of named arrays by the supplied fields
code by dholmes at jccc d0t net
function array_sort_by_fields(&$data, $sortby){
static $sort_funcs = array();
if (empty($sort_funcs[$sortby]))
{
$code = "\$c=0;";
foreach (split(',', $sortby) as $key)
{
$d = '1';
if (substr($key, 0, 1) == '-')
{
$d = '-1';
$key = substr($key, 1);
}
if (substr($key, 0, 1) == '#')
{
$key = substr($key, 1);
$code .= "if ( \$a['$key'] > \$b['$key']) return $d * 1;
";
$code .= “if ( $a[’$key’] < $b[’$key’]) return $d * -1;
”;
}
else
{
$code .= “if ( ($c = strcasecmp($a[’$key’],$b[’$key’])) != 0 ) return $d * $c;
”;
}
}
$code .= ‘return $c;’;
$sort_func = $sort_funcs[$sortby] = create_function(’$a, $b’, $code);
}
else
{
$sort_func = $sort_funcs[$sortby];
}
uasort($data, $sort_func);
}
Modifier: sortby - allows arrays of named arrays to be sorted by a given field
function smarty_function_sortby($arrData,$sortfields) {
array_sort_by_fields($arrData,$sortfields);
return $arrData;
}
Aufruf in TPL:
[{foreach from=$oFilterAttr->aValues|@sortby:"$oValue->value" item=oValue name=testInput}]
Danke!
Nachtrag: der Fehler bestand in der Benennung der Datei: statt function.sortby.php sollte es modifier.sortby.php heißen…