sujit prasad
sujit prasad

Reputation: 945

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.

Upvotes: 8

Views: 4886

Answers (1)

Khan Shahrukh
Khan Shahrukh

Reputation: 6361

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

Upvotes: 13

Related Questions