|currency 过滤器用于显示货币值。
{{ 100|currency }}此 Twig 过滤器是在安装了可在 October CMS 市场上获取的 Currency 插件 后引入的。您可以通过以下命令安装它。
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 }) }}显示货币以 长 或 短 格式
// $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']);