Skip to content
Miguel Saenz edited this page Apr 6, 2018 · 4 revisions

The Caffeinated Themes package comes with a handy Facade to make calling and loading theme pages easy within your code.

Themes

Components

Themes

Theme::all()

Get all themes.

Returns

Collection

Example

$themes = Theme::all();

Theme::getActive()

Returns the currently active theme.

Returns

string

Example

$activeTheme = Theme::getActive();

Theme::setActive($theme)

Sets the active theme that will be used to retrieve view files from.

(In Laravel 5.4+ use setCurrent)

Parameters

  • $theme (string) Theme slug. Required

Returns

null

Example

Theme::setActive('bootstrap-theme');

Theme::view($view, $data)

Renders the defined view. This will first check if the currently active theme has the requested view file; if not, it will fallback to loading the view file from the default view directory supplied by Laravel.

Parameters

  • $view (string) Relative path to view file. Required
  • $data (mixed) Any additional data you'd like to pass along to the view file to be displayed.

Returns

View

Example

$foo = 'bar';

return Theme::view('welcome', compact('foo'));

Theme::response($view, $data, $status, $headers)

Rendered the defined view in the same manner that Theme::view() does, but allows the means to set a custom status response and header for the rendered page.

Parameters

  • $view (string) Relative path to view file. Required
  • $data (mixed) Any additional data you'd like to pass along to the view file to be displayed.
  • $status (integer) HTTP status code.
  • $header (array) HTTP headers.

Returns

Response

Example

$posts = Post::orderBy('published', 'desc')->get();

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

Components

Component::register($name, $callback)

Register a new theme component. This will automatically register custom tags for both Blade and Twig (depending on which you are using), using the convention of component_$name.

Parameters

  • $name (string) The name you wish to give your theme component. Required
  • $callback (mixed) A callback method returning the desired data needed. Required

Returns

mixed

Example

Component::register('pageheader', function($title, $subtext) {
	return "<h1>{$title} <small>{$subtext}</small></h1>";
});