Zakro Gogolidze
Zakro Gogolidze

Reputation: 39

how to use variable inside laravel @include?

enter image description here

{{$one = 'testFileName'}}

@include('folder.project.$one')

Upvotes: 2

Views: 560

Answers (2)

Saman Ahmadi
Saman Ahmadi

Reputation: 687

First define variable in PHP tag (not {{ }})

@php($one = 'testFileName')

Second Use variable :

@include('folder.project'.$one)

Upvotes: 1

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

You can do that

First solution

{{$one = 'folder.project.testFileName'}}

@include($one)

second solution

{{$one = 'testFileName'}}

@include("folder.project.$one")

third solution

{{$one = 'testFileName'}}

@include("folder.project." . $one)

And for define variable you can also use

@php
    $one = 'testFileName';
@endphp

or (but it can depends of laravel version)

@php($one = 'testFileName')

Upvotes: 5

Related Questions