Today we'll go over an easy topic, we will look at how to give your users the ability to swap out views in your Laravel Packages.

Traditionally, you may develop a Package that requires view files. While this may be ok in some instances, it is usually more helpful for you to publish documentation for your Package's API and then allow your users to create their own layouts, templates, or views.

First let's look at how to use your own packages views: By convention your package views should go in src/views then you reference them with So in the our Laravel-Faq Package calling View::make for the view in src/views/home.blade.php would look like View::make('laravel-faq::home')

Simple enough, but in instances like the Laravel-Faq, I wanted to allow users to wrap the questions in any layout that they wanted to. So, once again, we create a configuration option to allow for this flexibility. In src/config/views.php I added a layout option and set it by default to laravel-faq::_layout. And in our src/views/home.blade.php we will @extend(Config::get('laravel-faq::views.layout')). Now if a user wanted to, they could change parameter and create their own layout with a @yield('content') section.

Finally, sometimes you may want to allow your users to specify a new location for their view files. Just add a views_path to the config and in your controller's constructor call: View::addLocation(Config::get('laravel-faq::views.views_path'))

This just scratches the surface of making your Laravel 4 Package views more flexible.