|currency 过滤器用于显示货币值。
{{ 100|currency }}此 Twig 过滤器在安装 Currency 插件 后引入,该插件可在 October CMS 市场获取。您可以使用以下命令安装它。
php artisan plugin:install Responsiv.Currency:::
该过滤器接受一个选项参数,该参数是一个支持多种值的数组。
| Option | Description |
|---|---|
| to | To a given currency code |
| from | From a currency code |
| format | Display format. Options: long, short, null. |
| site | Set to true to use currency codes from the site definition. Default: false. |
例如,将金额从美元兑换为澳元。
{{ 1000|currency({ from: 'USD', to: 'AUD' }) }}如果您想使用网站定义中的基础货币和显示货币,将 site 选项设置为 true。
{{ 1000|currency({ site: true }) }}以 long 或 short 格式显示货币。
// $10.00
{{ 1000|currency({ format: '' }) }}
// $10.00 USD
{{ 1000|currency({ format: 'long' }) }}
// $10
{{ 1000|currency({ format: 'short' }) }}你可以通过全局的 Currency 门面与货币功能进行交互。
例如,要将金额从 USD 转换为 AUD:
Currency::format(1000, ['from' => 'USD', 'to' => 'AUD']);以长格式或短格式显示货币
// $10.00 USD
Currency::format(1000, ['format' => 'long']);
// $10
Currency::format(1000, ['format' => 'short']);