您绝对可以,在您发布的链接上的“创建自定义输出修饰符”标题下,描述了如何将 sn-p 名称作为输出修饰符。此 sn-p 将在名为 $input 的变量中接收 [[+MoneyField]] 值。
所以你必须创建这个自定义的 sn-p,它可以像
一样简单
return '$'.number_format($input);
这样做的另一个版本是直接调用 sn-p 而不是像这样作为输出修饰符:
[[your_custom_money_format_snippet ? input=`[[+MoneyField]]`]]
我不确定在这种情况下两者之间是否有任何区别。显然,当您将其作为 sn-p 而不是输出修饰符调用时,您可以将任何值传递给数字格式 sn-p。而且我敢肯定两者之间存在微秒的性能差异,但恐怕我不知道哪一个会赢。 ;)
更新:
实际上找到了您要在此链接上实现的确切示例;
http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-%28output-modifiers%29/custom-output-filter-examples
片段:
<?php
$number = floatval($input);
$optionsXpld = @explode('&', $options);
$optionsArray = array();
foreach ($optionsXpld as $xpld) {
$params = @explode('=', $xpld);
array_walk($params, create_function('&$v', '$v = trim($v);'));
if (isset($params[1])) {
$optionsArray[$params[0]] = $params[1];
} else {
$optionsArray[$params[0]] = '';
}
}
$decimals = isset($optionsArray['decimals']) ? $optionsArray['decimals'] : null;
$dec_point = isset($optionsArray['dec_point']) ? $optionsArray['dec_point'] : null;
$thousands_sep = isset($optionsArray['thousands_sep']) ? $optionsArray['thousands_sep'] : null;
$output = number_format($number, $decimals, $dec_point, $thousands_sep);
return $output;
用作输出修饰符:
[[+price:numberformat=`&decimals=2&dec_point=,&thousands_sep=.`]]