sfarzoso
sfarzoso

Reputation: 1600

How to display a php variable within js using the blade engine?

I have a view which call the bootbox plugin to display a modal, the message of this modal is the following:

'confirm_invite'    => 'The :user has invited you, do you want accept?',

This is my view:

@extends('boilerplate::layout.index', [
'title' => __('boilerplate::layout.dashboard'),
'subtitle' => 'Components & plugins demo',
'breadcrumb' => ['Components & plugins demo']]
)

@section('content')

    @isset($invite)
        @push('js')
            <script>
                bootbox.confirm({
                    title: `{{ __('invites.invite_received', ['user' => $invite->user->first_name]) }}`,
                    message: `{{ __('invites.confirm_invite') }}`,
                    callback: function(result) {
                        if (result) {
                            alert('hello there');
                        }
                    }
                })
            </script>
        @endpush
    @endisset

    @include('boilerplate::plugins.demo')
@endsection

The modal appears correctly but the :user field isn't replaced by the variable, I can still see The :user has invited you, do you want accept?

Upvotes: 2

Views: 49

Answers (1)

mgottsch
mgottsch

Reputation: 799

I think you forgot to pass the user as a second argument to the __ function.

Try changing

__('invites.confirm_invite')

to

__('invites.confirm_invite', ['user' => $invite->user->first_name])

Upvotes: 1

Related Questions