AnAlien's avatar

how to make variable for "@yield"

Blade on how to make PHP variable for "@yield". ?


//Standard Yield
@yield('content')

//I want to do... (call pages by name.)
@yield($variable)

0 likes
9 replies
ftiersch's avatar

What do you mean by "call pages by name"? If I understand you correctly I think you're looking for @include, not @yield

@yield would change the name of the section the inheriting template needs to overwrite

AnAlien's avatar

No. What I am looking for is not "include". Example: When someone clicks on the homepage link, the homepage template should be loaded. I will do this automatically, not with "route".

AnAlien's avatar

Isn't it clear? @niyo How do I place a variable in "Yield"?

mohrad's avatar
mohrad
Best Answer
Level 3

whatever inside the yield function is a variable itself @yield('content') for example "content" is variable declared in the blade file you are extending from!

so you may use

@yield('variable')

and in the blade you extend

@section('variable', 'what ever you need to display')

you might need to change the value so you may use something like this

$variable = "content";

@section('variable', $variable)
1 like
vainway 's avatar

on this @extends put your file where it is located ex: folder(layouts) your file name.blade.php

1 like

Please or to participate in this conversation.