Reputation: 545
While creating a basic item detail page for a basic blog I've run into a problem with Laravel's @extends not working when pulling in a master layout template. The content from the detail page loads just fine but the master page HTML is not there at all and I'm not getting any errors.
In my routes:
Route::get('blog', 'BlogController@public_index');
Route::get('blog/{id}', 'BlogController@public_single');
In my BlogController:
public function public_single($id) {
$blog = Blog::find($id);
return View::make('public.blog_single') -> with('blog', $blog);
}
At the very top of the blog_single template:
@extends('layouts.public')
All other templates that use this master layout work as expected.
My views directory structure:
views
|
|layouts
| |
| | admin.blade.php
| | public.blade.php
|
|public
|
|blog.blade.php
|blog_single.blade.php
One thing I'm wondering is if the fact that this page looks like it's rendering from a subdirectory is an issue. Here is an example:
This works:
www.mydomain.com/blog
This doesn't:
www.mydomain.com/blog/1
I've looked through the Laravel docs and don't see an answer there. Any ideas? Thanks.
Upvotes: 2
Views: 1448
Reputation: 73
Have you tried to add an absolute path to the master style references?
For example:
<link rel="stylesheet" href="css/bootstrap.min.css">
Has to be:
<link rel="stylesheet" href="/css/bootstrap.min.css">
In all the url's we use. This worked for me :)
Upvotes: 2
Reputation: 545
Okay, not sure how this fixed it, hopefully someone can give me a little detail.
I found this line of code at the bottom of the blog_single.blade.php file:
<div class="text-center">{{ $blogs->links() }}</p>
That is leftover from a copy/paste of the blog.blade.php file and obviously on a detail page I don't need pagination. I removed that one line of code and now the templates work as they should. Wondering why Laravel did not throw some sort of error if it was choking on that line, or why that line would effect the whole master file from getting included in the first place.
Anyway, it's fixed.
Upvotes: 1