Skip to content

Views And Responses

Shea Lewis edited this page Jun 24, 2015 · 1 revision

Views & Responses

Below you will find instructions on how to call and return Theme views and responses from your application.

Views

Theme view files are loaded and returned through the Theme::view facade method in place of using Laravel's View method:

return Theme::view('welcome', $data);

Behind the scenes, Caffeinated Themes will follow through a cascade loaded approach to finding the desired view file. Continuing with our example above, these are the steps that will be taken to loading a view file:

  1. First, it will check the currently active theme: public/themes/active-theme/views/welcome.blade.php
  2. If not found within your theme, it will fallback to the default views directory for your Laravel application: resources/views/welcome.blade.php
  3. If the view can't be found, an exception will be thrown as normal.

Caffeinated Modules Support

If you are also using the Caffeinated Modules package, you're in luck as Caffeinated Themes will take this into consideration! When loading a view, Caffeinated Themes will check to see if the view path starts with modules/yourModule (e.g. modules/blog/view). If so, it'll add the modules view directory to it's cascade fallback:

  1. First, it will check the currently active theme: public/themes/active-theme/views/modules/blog/view.blade.php
  2. If not found within your theme, it will fallback to the views directory for your module: app/Modules/Blog/Resources/Views/view.blade.php.
  3. If not found within your theme or module, it will fallback to the default views directory for your Laravel application: resources/views/modules/blog/view.blade.php
  4. If the view can't be found, an exception will be thrown as normal.

Hint: You can also use the more OOP-style of using . (periods) as directory separators in place of / (forward slashes):

return Theme::view('pages.about', $data);

Responses

Returning theme view responses is the same as Laravel's Response::view method. The only difference being, the view returned will go through the Theme::view method.

return Theme::response('modules.blog.rss.index, compact('posts'), 200, [
    'Content-Type' => 'application/atom+xml; charset=URF-8'
]);

Extending Theme Views

You may define the layout you wish to extend from within your controllers using the following method:

Theme::setLayout('layouts.master');

Notice: Be sure to set your active theme before setting the layout.

Once you've set layout, you may extend the layout as follows from within your view files:

Blade:

@extends($theme_layout)

Twig:

{% extends theme_layout %}