0

동적 목록 placeholder을 만들 때이 자리 표시 자에있는 값 중 일부는 돈을 나타내는 것으로 간주되는 십진수입니다.자리 표시 자 출력 형식

내가 표시하도록 형식을 지정할 수있는 방법이 있다면 궁금합니다. 내가 http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers)를 볼 수 있지만 내가 여기서 할 수있는 방법이 표시되지 않습니다 [[+MoneyField:formatmoney]]

같은

뭔가.

답변

3

게시자가 게시 한 링크에서 "맞춤 출력 수정 자 생성"헤더 아래에 출력 수정 자로 스 니펫 이름을 배치하는 방법이 나와 있습니다. 이 스 니펫은 $input이라는 변수에 [[+MoneyField]] 값을 수신합니다.

[[your_custom_money_format_snippet ? input=`[[+MoneyField]]`]] 
:

그래서 당신은

return '$'.number_format($input); 

이 스 니펫을 호출하는 일을 대신 직접 때문에 같은 출력 수정 등의 또 다른 버전으로 간단 수이 사용자 정의 조각을 만들어야 할 것

이 경우 두 가지 차이점이 있는지 확실하지 않습니다. 당연히 출력 한정자 대신 스 니펫으로 호출 할 때 숫자 형식 스 니펫에 모든 값을 전달할 수 있습니다. 그리고 나는 그 둘의 성능 차가 마이크로 초라고 확신하지만 어느 것이 승리 할 지 모르겠습니다. ;)

업데이트 : 실제로이 링크에서 구현하려는 정확한 예를 발견했습니다. 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=.`]] 
+0

좋은 크리스티안은, 몇 분 시도 할 것이다 – Kevin