Welcome Guest, Not a member yet? Register   Sign In
Not just another template system (with screencast)
#1

[eluser]philpalmieri[/eluser]
Not just another template system (with screencast)

So we have been working on this template system that we are now sharing. We built it to separate not only the design from the application, but the designers themselves. Follow with me for a minute: we use 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.

I know it sounds a bit hacky, but its actually really efficient.

Code:
/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.

Code:
//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

Download:
http://www.page12.com/ci/viewlib/ViewLib.zip

Default Demo templates
http://www.page12.com/ci/viewlib/templates.zip


Messages In This Thread
Not just another template system (with screencast) - by El Forum - 11-06-2008, 09:21 AM
Not just another template system (with screencast) - by El Forum - 11-06-2008, 02:18 PM
Not just another template system (with screencast) - by El Forum - 11-06-2008, 05:13 PM
Not just another template system (with screencast) - by El Forum - 11-07-2008, 07:25 AM
Not just another template system (with screencast) - by El Forum - 11-07-2008, 08:26 AM
Not just another template system (with screencast) - by El Forum - 11-07-2008, 08:28 AM
Not just another template system (with screencast) - by El Forum - 10-11-2009, 07:47 AM
Not just another template system (with screencast) - by El Forum - 10-12-2009, 11:29 AM
Not just another template system (with screencast) - by El Forum - 10-12-2009, 11:32 AM
Not just another template system (with screencast) - by El Forum - 10-19-2009, 05:12 AM
Not just another template system (with screencast) - by El Forum - 10-19-2009, 05:49 AM
Not just another template system (with screencast) - by El Forum - 10-21-2009, 10:49 AM
Not just another template system (with screencast) - by El Forum - 04-08-2011, 08:41 AM
Not just another template system (with screencast) - by El Forum - 04-09-2011, 11:33 PM
Not just another template system (with screencast) - by El Forum - 04-10-2011, 01:00 AM
Not just another template system (with screencast) - by El Forum - 04-10-2011, 02:30 AM
Not just another template system (with screencast) - by El Forum - 04-10-2011, 02:33 AM
Not just another template system (with screencast) - by El Forum - 04-11-2011, 04:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB