template/layout.blade.php
JavaScript
x
<title>@yield('title', 'Default')</title>
test23.blade.php
JavaScript
@extends('template.layout')
@if($test == 1)
<p>Done</p>
@yield('test')
@endif
TestController.php
JavaScript
class TestController extends Controller
{
protected function getVars()
{
$title = "Funziona2s";
$test = 1;
//return view('test23', compact('title', 'test'));
return view('test23')
->withTitle('Titoloxd')
->withTest(1);
}
}
the variables Title and Test I’ve passed are both not showing, anyone knows how to fix?
Advertisement
Answer
@yield is used to “place” the content of a @section somewhere.
You are passing the variables via the controller into the views. So you can just use the variables as blade variables like this:
JavaScript
<title>{{ $title }}</title>
And
JavaScript
@if($test == 1)
<p>Done</p>
{{ $test }}
@endif