Skip to content

Latest commit

 

History

History
50 lines (31 loc) · 1.79 KB

Money-Twig.md

File metadata and controls

50 lines (31 loc) · 1.79 KB

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!

Money Documentation

How to use the Money Twig Extension

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:

  1. Register the extension in your Symfony's configuration;
  2. Use the extension in your Twig templates.

STEP 0: Install twig/intl-extra

composer req twig/intl-extra

STEP 1: Register the extension in your Symfony's configuation

Open the file /config/packages/twig.yaml.

Add the extension to the configuration:

services:
    ...
    SerendipityHQ\Component\ValueObjects\Money\Bridge\Twig\MoneyFormatterExtension: ~

STEP 2: Use the extension in your Twig templates

Using localizedmoney filter

When you know you are using the MoneyInterface object, then you use this filter:

{{ user.balance|localizedmoney }}

Using localizedmoneyfromarr filter

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!