Timo.Klement
Timo.Klement

Reputation: 637

Laravel: How to find the right blade master template?

To extend a blade template you have to write

@extends('folder.template_name')

This works for standard installation.

I've created a module for the backend and now I can't use my module template because Laravel catches the first record and that is the standard view folder.

My structure looks like this:

app
-- modules
-- modules\backend
-- modules\backend\views
-- modules\backend\views\layouts\master.blade.php
-- views
-- views\layouts\master.blade.php

So when I'm in the backend and try to display my template:

// app\modules\backend\views\page\index.blade.php
@extends('layouts.master')

Laravel renders the app\views\layouts\master.blade.php instead of app\modules\backend\views\layouts\master.blade.php

I've tried many names inside that @extends e.g.

@extends('app\modules\backend\views\layouts\master')
@extends('app.modules.backend.views.layouts.master')
@extends(base_path(). '\app\modules\backend\views\\' . 'layouts.master')

Nothing works.

Upvotes: 1

Views: 2782

Answers (2)

Gadoma
Gadoma

Reputation: 6565

While using a package or autoloaded module, referring to it's resources is done using the double colon notation. In your case, to access the module's master template you need to use

@extends('backend::layouts.master') 

These conventions are described in the docs, for further info please refer to

Laravel 4 package conventions

Upvotes: 5

Abba Bryant
Abba Bryant

Reputation: 4012

Make sure /app/config/view.php has a path entry for where those views are located.

I.E.

'paths' => array(__DIR__.'/../views'),

To

'paths' => array(
    __DIR__.'/../views',
    __DIR__.'/../modules/backend/views'
),

or whatever represents your actual path.

From here you might want to look into doing the view folder loading via another mechanism if your views are in dynamically generated folders. Maybe a module::boot event that adds the module path to the view paths array? Just an idea.

Upvotes: 0

Related Questions