1

This is my code in laravel blade

 @foreach($modules as $module) // {{ mod.$module['module_name'] }} giving me right value @section('content') @include("mod.$module['module_name']") // mod is my folder name and $module['module_name'] value is coming from database @endsection @endforeach 

{{ mod.$module['module_name'] }} is giving me correct value but when i pass it to @include it gives me error. Please help me !!!

4
  • What is the error? In general here, the more details you give the better answers you get. I don't remember the syntax for the include command but I know that what you have a syntax error if this were plain PHP. Have you tried @include("mod.{$module['module_name']}")? Commented Jun 23, 2017 at 19:34
  • error => syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) Commented Jun 23, 2017 at 19:37
  • yes i tried @include("mod.{$module['module_name']}") but stiil get error Commented Jun 23, 2017 at 19:44
  • You should include relevant line from your compiled template. Looking at that error, my suspicion is that laravel doesn't support doing that the way you are trying to do that... back in a few Commented Jun 23, 2017 at 19:49

1 Answer 1

3

I think it has to do with the way the blade template translates the @include directive into compiled PHP. Including the snippet from the compiled PHP file would help, but try this:

@include( 'mod.' . $module['module_name'] ) 

Looking at some of my past code, you can definitely use a variable in an include. In my case I simply built the desired filename in the controller and passed it along to the view, so my include statement was simply:

@include( $filename ) 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks bro , @include( 'mod.' . $module['module_name'] ) solution work like a charm. Thanks a lot
I appreciate your effots

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.