Reputation: 1262
i have this Route code
Route::get('/{slug}', function($slug) {
return View::make('page');
});
...let say, my url $slug
is "about" as the value, inside my page.blade.php
will need to see this $slug
"about" and output it as @include('modules.page.$slug')
where the $slug
should be the about in short, i would like to happen that my @include
read this $slug
as my dynamic name to call different page.
@section('content')
@include('modules.page.$slug')
@include('layouts.creic')
@stop
is this possible?
Upvotes: 1
Views: 156
Reputation: 466
First of all, you should pass the $slug variable to your view like this:
<?php
Route::get('/{slug}', function($slug) {
return View::make('page', array('slug' => $slug));
});
And, in your blade view... Don't use single quotes when you're using variables.
@include("modules.page.$slug")
Upvotes: 1
Reputation: 25435
Well, you could always fetch it from the Request class:
@section('content')
@include('modules.page.'.Request::segment(1))
@include('layouts.creic')
@stop
Alternatively, you could pass it down to the view:
Route::get('/{slug}', function($slug) {
return View::make('page')->with('slug', $data);
});
And access it like you already do:
@section('content')
@include('modules.page.'.$slug)
@include('layouts.creic')
@stop
Upvotes: 1