diff --git a/docs/laravel.md b/docs/laravel.md index f69aa77..0246dc2 100644 --- a/docs/laravel.md +++ b/docs/laravel.md @@ -286,6 +286,45 @@ class BookController flash()->add{{ type | capitalize }}('{{ message }}', '{{ title }}'); ``` +

Variables

+ +Presets can also contain variables that can be substituted by using the translation system. Take the following example where you have a preset showing a personalised welcome message to the user. + +```php + [ + 'hello_user' => [ + 'type' => '{{ type }}', + 'message' => 'welcome_back_user', + ], + ], +]; +``` + +In the translations file you can define `welcome_back_user` with the message containing the variable `:username`. + +```php + 'Welcome back :username', +]; +``` + +If you want to substitute the `:username` in the above translation with a username in the controller, you can achieve this by passing an array of values to be substituted as the second argument. + +```php +class BookController +{ + public function save() + { + $username = 'John Doe'; + + flash()->addPreset('hello_user', ['username' => $username]); +``` + --- ## Dark Mode diff --git a/docs/symfony.md b/docs/symfony.md index 74c46f0..a2c3af7 100644 --- a/docs/symfony.md +++ b/docs/symfony.md @@ -266,6 +266,40 @@ class BookController flash()->add{{ type | capitalize }}('{{ message }}', '{{ title }}'); ``` +

Variables

+ +Presets can also contain variables that can be substituted by using the translation system. Take the following example where you have a preset showing a personalised welcome message to the user. + +```yaml +# config/packages/flasher.yaml + +flasher: + presets: + hello_user: + type: {{ type }} + message: welcome_back_user +``` + +In the translations file you can define `welcome_back_user` with the message containing the variable `:username`. + +```yaml +# translations/flasher.en.yaml + +welcome_back_user: Welcome back :username +``` + +If you want to substitute the `:username` in the above translation with a username in the controller, you can achieve this by passing an array of values to be substituted as the second argument. + +```php +class BookController +{ + public function save() + { + $username = 'John Doe'; + + flash()->addPreset('hello_user', ['username' => $username]); +``` + --- ## Dark Mode