1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【CraftCMS】金額のFormatで半角の「¥」を出力したい

Last updated at Posted at 2019-05-01

数値フィールドを半角の¥でフォーマットしたいけどなぜだか全角の¥が表示されてしまう。

{{entry.money|currency("JPY")}} {# コレ全角→¥100 #}

currencyを定義しているソースをホジホジしてみると
currencySymbolsの定義が全角になってた。

craft/vendor/craftcms/cms/src/config/locales/ja.php
    'currencySymbols' => [
        ・・・
        'JPY' => '¥', //74行目くらい
        ・・・
    ];

ここはコアモジュールなのでイジったところでCMSアップデートが走ると元に戻ってしまうので
どうしたもんかなーと中の人にたずねてみたら

一番ラクなのはreplaceのFilterを使うことだぜ!

という返事を貰ったので
こうしたらまぁ解決したけどちょっと見づらいからtranslationsとかで設定出来たらなぁ…なんて。

{{entry.money|currency("JPY")|replace({"¥":"¥"})}}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?