03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

File-Based CMS 349<br />

99 }<br />

100 }<br />

.<br />

This file should be saved as app/controllers/IndexController.php.<br />

In the IndexController class, we’ve injected the same two dependencies: $filesystem and $engine.<br />

We need these to fetch and extract the template data.<br />

We begin by fetching all the files in the app/views/pages directory. We iterate through them filtering<br />

out all the returned items which have a type of file. From these, we fetch the metadata and check<br />

if the route defined matches that which is being requested.<br />

If there is a match, we extract the template data and save it to a new file, resembling app/views/-<br />

pages/extracted/[original name]. We then fetch the layout defined in the metadata, performing a<br />

similar transformation. We do this because we still want to run the templates through Blade (so that<br />

@extends, @include, @section etc.) all still work as expected.<br />

We filter the page metadata and the layout metadata, to omit any items which do not have values,<br />

and we pass the merged array to the view. Blade takes over and we have a rendered view!<br />

Extending The CMS<br />

We’ve implemented the simplest subset of October functionality. There’s a lot more going on that I<br />

would love to implement, but we’ve run out of time to do so. If you’ve found this project interesting,<br />

perhaps you would like to take a swing at implementing partials (they’re not much work if you<br />

prevent them from having metadata). Or perhaps you’re into JavaScript and want to try your hand<br />

at emulating some of the Ajax framework magic that October’s got going on…<br />

.<br />

You can learn more about OctoberCMS’s features at: http://octobercms.com/docs/cms/themes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!