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 315<br />

41 <br />

42 <br />

43 <br />

44 <br />

45 {{ \$title }}<br />

46 <br />

47 <br />

48 <br />

49 {{ \$message }}<br />

50 <br />

51 <br />

52 ");<br />

53<br />

54 $data = $this->parseMeta($parts["meta"]);<br />

55 $template = $this->minify($parts["html"]);<br />

56<br />

57 return $this->engine->render($template, $data);<br />

58 }<br />

.<br />

This was extracted from app/controllers/IndexController.php.<br />

This time round, we’re using an extractMeta() method to pull the meta data string out of the<br />

template string, and a parseMeta() method to split the lines of metadata into key/value pairs.<br />

The result is a functional means of storing and parsing meta data, and rendering the remaining<br />

template from and to a string.<br />

.<br />

The minify method is largely unmodified from the original, which I found at: http://stackoverflow.com/questions/6225<br />

to-minify-php-page-html-output.<br />

Creating Layouts<br />

We need to create some sort of admin interface, with which to create and/or modify pages and<br />

layouts. Let’s skip the authentication system (as we’ve done that before and it will distract from the<br />

focus of this tutorial).<br />

I’ve chosen for us to use Flysystem when working with the filesystem. It would be a good idea to<br />

future-proof this dependency by wrapping it in a subclass which implements an interface we control.

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

Saved successfully!

Ooh no, something went wrong!