Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change extends(layout) dynamically in laravel 5

I have been trying to change layout dynamically in laravel by just passing a variable in

@extends('default1.master')

to

$var = default2
@extends('$var.master')

possibly

@extends($var.'.master')    

tried a lot but unable to find a solution all I get is error in my syntax or view not found.

like image 468
sujit prasad Avatar asked Jun 17 '15 10:06

sujit prasad


1 Answers

in your view you can pass a variable with the view name like

@extends('layout.'.$view)
//or
@extends($view.'.base')

here $view is a variable which stored the view name from controller my controller looks following

$view = 'base';
return view('someview', compact('view'));

and if by any chance you are declaring this $var in the view file only you should not forget to enclose it in

<?php ?> tag
like image 186
Khan Shahrukh Avatar answered Nov 14 '22 16:11

Khan Shahrukh