Skip to content

p12 Templates

Derek Jones edited this page · 6 revisions
Clone this wiki locally

Category:Library::Template Engine page12 Template System

v 1.0

We built it to separate not only the design from the application, but the designers themselves. It uses a cascading template that includes main outer templates, header, footer and content areas, along with css/js.

Basically, the template system uses the URL to decide which template to parse, based on the file system path.

URL: "site.com/foo/bar" will look in the template folder and use the document, content, header & footer.

Then it looks in foo, if foo containes a doc, head, footer, or content it will override the previous one and use it.

Each level can also include a css and js folder. This is useful so you can override styles based on the section of the site your in.

For the system to work you need to create at least a document.php, header.php, content.php, and footer.php in the root of your template folder.


/templates
  - document.php
  - content.php
  - header.php
  - footer.php
  - /css
  - /js
  - /store
  --- store.php
  --- /css
  --- /viewProduct
  ----- document.php
  ----- viewProduct.php

You can pass variables, set custom areas, and override the templates at any point too. so for some code:

We chose to call it "view" so that we don't confuse anybody internally who is used to working with views. Also, we still use CI views, but we use them as reusables for our modules. Those views then get passed into variables to use in the template.


//Load the lib
$this->load->library('view');

//Render Template
$this->view->render();

//Set Variables
$this->view->set("content", "variable", "value");
$this->view->set("content", $assocArray);
$this->view->set("header", "activePage", "products");
$this->view->set("content", "news_list", $this->load->view("news_list", $news, TRUE));

//Append Values
$this->view->append("document", "pageTitle", "Product XYZ");

//Override template
$this->view->override("content", "customTemplate.php");

//Render for AJAX
$this->view->render(TRUE); // will render just the content file without the outer templates

Future: Pulling the JS/CSS minifying and even variable parsing/caching We will pull it out of our SVN soon and stick it on google code or something, but for now i'll just keep posting the zip files as we upgrade.

8 Minute Screencast http://vimeo.com/2170796 (go full screen, color sucks.)

Download: Version 1.0

Something went wrong with that request. Please try again.