devo devo -4 years ago 321
PHP Question

How to load view from alternative directory in Laravel 4

In my Laravel 4 application's root directory, I have a folder

. Inside the
folder, I have
How can I access view from this
folder in a specific route.

Route::get('{slug}', function($slug) {
// make view from themes/default here

My directory structure:





I need to load views from
folder. Please explain this.

Answer Source

Here I am not accessing my project from public folder. Instead of this I am accessing from project root itself.

I have seen a forum discussion about Using alternative path for views here. But I am little confused about this.The discussed solution was,

You'd add a location like,


Then add namespace for theme,

View::addNamespace('theme', '/path/to/themes/views');

Then render it,

return View::make('');

What will be the value for /path/to/ ?

Can I use the same project in different operating system without changing the path?

Yes, we can do this using the following,

Put the following in app/start/global.php

    View::addNamespace('theme', app('path').'/themes/default');

Then call view like the default way,

    return View::make('page');

This will render page.php or page.blade.php file from project_directory/app/themes/defualt folder.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download