duncan3dc / blade

Use Blade templates without the full Laravel framework
Apache License 2.0
145 stars 36 forks source link

Extend template from another folder #4

Closed rafatrace closed 8 years ago

rafatrace commented 8 years ago

Hi, imagine the following folders structure

└── app/
    ├── layouts/
    │   ├── master.blade.php
    │   └── login.blade.php
    └── packages/
        ├── users/
        │   ├── list.blade.php
        │   └── add.blade.php
        └── products/
            ├── list.blade.php
            └── add.blade.php

I've added booth app/layouts/ and app/packages/ to the Blade instance. When I render products.list without extending it works fine, as well as if I render master or login.

But when I try to @extends('master') in list.blade.php it doesn't work because it will look only in that folder that it is already in. For example in users folder only.

How can you achieve this? Cheers.

duncan3dc commented 8 years ago

I'm struggling to reproduce your issue. I've created a test here and it seems to work as expected.

"view11" extends "base-alt" which is in a different path that has been added using addpath().

Can you put up a small example repo with the code demonstrating the issue?

rafatrace commented 8 years ago

I was implementing this in a wrong way, my bad. Another thing, is there a way to delete paths or does this happens automatically?

Imagine my situation: I have, UsersController, BooksController and AuthorsController, on everyone one of this I'm adding paths for each controllers, since users views are stores in a different path, like in the example above.

If I go to users, then books, then authors my paths array will have this 3 paths to search for blade files in it. If I go to users again will it add Users path again, and make 4 paths on the array?

What about a deletePath method? I mean, it will be less consumable if when I'm going to users controller it will search views only in users path instead of going to author path, then to books and finally to the users. Maybe your class does this already and I didn't find it.

Thanks for your time and work.

duncan3dc commented 8 years ago

The paths are managed by the underlying project and they don't offer any kind of deletePath.

You could create a copy of your blade instance to pass to your controller, then adding the controller specific path wouldn't affect the parent instance, something like:

$blade = new BladeInstance;

$blade->addPath("default");

$usersBlade = clone $blade;
$usersBlade->addPath("users");
rafatrace commented 8 years ago

That seem like a nice implementation to my use case. Thanks again @duncan3dc

Cheers