Skip to content
Advertisement

@yield does not show content on Laravel

template/layout.blade.php

<title>@yield('title', 'Default')</title>

test23.blade.php

@extends('template.layout')

@if($test == 1)
    <p>Done</p>
    @yield('test')
@endif

TestController.php

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:

<title>{{ $title }}</title>

And

  @if($test == 1)
    <p>Done</p>
    {{ $test }}
  @endif
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement