I need to pass a variable to an included Blade file. I have attempted this two-ways; however, neither have been successful.
Pass a variable, title
, to the included file:
@section('left')
@include('modal', ['title' => 'Hello'])
@stop
Use @yield
and set the section:
@section('left')
@include('modal')
@section('title')
Hello
@stop
@stop
I am using Laravel 4.2. I am unaware if what I am trying to do is possible, but I imagine it is.
The blade templates are stored in the /resources/view directory. The main advantage of using the blade template is that we can create the master template, which can be extended by other files.
Blade is very fast, because it is simply a handful of regular expressions that are run against your templates to compile them to pure PHP.
One of blade directive @stack('scripts') is very helpful when you have javascript need to execute in the child page. I create a fresh Laravel installation to demo an example. I have to make auth scaffolding with laravel/ui package because I'm using Laravel 6.
According to the documentation, the include
-way should be the way to do it:
Including Sub-Views
@include('view.name')
You may also pass an array of data to the included view:
@include('view.name', array('some'=>'data'))
My hunch is that $title
is conflicting with another variable in your nested templates. Just for troubleshooting, try temporarily calling it something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With