extending/including default view?
Closed this issue · 2 comments
Is there a way to @extend
or @include
the corresponding view from the default theme (or from the standard resources/view folder) in a theme?
For example, if I have a fairly complex view in the default theme, and I want to override some parts, perhaps a single @section
in a theme, what's the best way to do that without duplicating the code from the default theme?
Laravel will pick a the first view file in your theme folder and look no further...
My proposals:
A) Have you tried to use a relative (to your theme) path?
ie @extends("..\baseview")
B) The correct way would be to split your complex view into two views:
common_parts.blade.php
theme_specific_parts.blade.php (which extends the previous)
and override only the second view on your theme. So no duplicating code for the common parts!
Yes, I realize splitting the complex view is probably the best way to go, at least long term, but I'd still be interested in another option.
The particular use case I have in mind is actually a "demo"-theme, adding additional comments and instructions on some pages. Would it make sense to write a Blade extension, basically creating a stupid @extends
that only looks for files in the standard resources/views-tree?
A sort-of working solution is to add another level of indirection in the views I'd like to augment/extend.
Replace the default view example.index
by something like:
@extends('layout.base')
@include('example.index.index`)
where example.index.index
contains the actual view. Then the theme can override example.index
with
@extends('layouts.base')
@include('example.index.index')
@section('demo')
Additional content here
@stop
but it doesn't feel very elegant.