Contentful Templates for CodeIgniter |
[eluser]Unknown[/eluser]
Github Repository: https://github.com/shawndellysse/codeigniter-contentful From the much-better-formatted README(https://github.com/shawndellysse/codeign...E.markdown): What is Contentful? Heavily inspired by Rails 3's template system, Contentful is a templating library for CodeIgniter (tested on 2.0.1 Reactor) and PHP 5. It allows you to easily keep your layouts and views compeletely separate from your controllers. It also lets the individual view apply changes to your layouts. Installation 1. Download either the tarball(https://github.com/sdellysse/codeigniter...all/master) or the zipball(https://github.com/sdellysse/codeigniter...all/master), depending upon your poison of choice, and extract it. 2. Copy the contents of the extracted directory to your CodeIgniter project root. 3. That's it. It comes with an example controller/layout/view combination for testing purposes. Assuming your project url is http://localhost/ci, point your web browser to http://localhost/ci/index.php/contentfultest. Usage In your controller: Code: class ContentfulTest extends CI_Controller { This will load the library, set a variable in the view, and then load your layouts and views. Since you didn't specify otherwise, it will look for your layout in Code: application/views/layout/default.html.php Code: application/views/contentfultest/index.html.php In your layout: Code: <html> The Code: contents_of($section) Code: content_for Code: contents_of Code: body-class Code: <?php echo trim(contents_of('body-class')) ?> Code: contents_of('some-section', 'a', 'b', 'c') Code: a(b(c(contents_of('some-section')))) In your view: Code: <?php content_for('title') ?> Each Code: content_for($section) Code: contents_of($section) Code: content_for When run with the above layout, view, and controller (with a little bit of tidying): Code: <html> Configuration ------------- Edit Code: application/config/contentful.php Code: application/config/contentfulmanager.php Edit: Due to feedback, 'yield' became 'contents_of'. It is more fitting with the name, and more readable. Thanks _druu. |
Welcome Guest, Not a member yet? Register Sign In |