Do you like this library? Leave a ★ or run composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!
NOTE: You can read more about Twig extensions in Symfony here: How to Write a custom Twig Extension
To use the Twig Extension of Money, you have to follow those steps:
- Register the extension in your Symfony's configuration;
- Use the extension in your Twig templates.
composer req twig/intl-extra
Open the file /config/packages/twig.yaml
.
Add the extension to the configuration:
services:
...
SerendipityHQ\Component\ValueObjects\Money\Bridge\Twig\MoneyFormatterExtension: ~
When you know you are using the MoneyInterface
object, then you use this filter:
{{ user.balance|localizedmoney }}
When you don't have a MoneyInterface
object but an array
built to create a MoneyInterface
object (like $money = ['humanAmount' => 1000,00, 'currency' => 'EUR']
), then you can use the filter localizedmoneyfromarr
: internally it first creates a MoneyInterface
object and then formats it.
{{ user.balanceArray|localizedmoneyfromarr }}
Do you like this library? Leave a ★ or run composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!