CodeIgniter Forums

Full Version: Not just another template system (with screencast)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[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

El Forum

[eluser]ray73864[/eluser]
The screencast needs major improvements, it has a 'HD Preview' watermark across it and your colour scheme for 'TextMate' (black background) makes it hard to follow what you are doing.

El Forum

[eluser]philpalmieri[/eluser]
Sorry was my first screencast.

The origional (much easier to read than on vimeo) is at
http://www.page12.com/ci/viewlib/introduction.mov

For the watermark, didn't think it was that bad and didn't want to spend the $60 to buy the app

Phil

El Forum

[eluser]Maxximus[/eluser]
Thanks for sharing, it looks promising for sure! Screencast helped a lot to get a quick grip on it. Will give it a go next week.

One question right now: somewhere in you screencast you mentioned css files needs a .css extension. Because I compress my CSS (and JS), I save the compressed files with a .php extension (and add cache control in it).
Will that give any issues?

@ray: Wasn't that bad. Have seen torrents far worse.

El Forum

[eluser]philpalmieri[/eluser]
actually, now that you mention it - any file in the css/js folder will get picked up.

El Forum

[eluser]philpalmieri[/eluser]
Also, would love constructive feedback on the screencast - aside from the TM theme, I was thinking of buying the software and doing a regular posting of them. I wasn't sure if there was a big enough demand for the videos.

Phil

El Forum

[eluser]patak[/eluser]
Hi,
I found your extension and I am trying to build my own application.
The application is in directory www root and I have error while render template.
This is application tree
Code:
wwwroot
- /app/
-- /system/
--- /application/
---- /config/
---- /controllers/
----- viewlib.php
---- /and other standard folders and files of standard CI + your p12 templates files/
-- /templates/
--- /css/
--- /js/
--- /viewlib/
---- viewlib.php
--- content.php
--- document.php
--- header.php
--- footer.php
All files from your p12 package are unchanged except of views.php in config folder in which I change
Code:
$config['template_dir'] = "/templates/";
to
Code:
$config['template_dir'] = "/app/templates/";

When go to http://localhost/app/index.php/viewlib I get this errors
Code:
A PHP Error was encountered

Severity: Warning

Message: include(C:/Users/patakj/Documents/vyvoj/xampp/htdocs/templates/document.php) [function.include]: failed to open stream: No such file or directory

Filename: libraries/View.php

Line Number: 121
A PHP Error was encountered

Severity: Warning

Message: include() [function.include]: Failed opening 'C:/Users/patakj/Documents/vyvoj/xampp/htdocs/templates/document.php' for inclusion (include_path='.;C:\Users\patakj\Documents\vyvoj\xampp\php\pear\')

Filename: libraries/View.php

Line Number: 121
When I change
Code:
$config['template_dir'] = "/app/templates/";
back to
Code:
$config['template_dir'] = "/templates/";
I get this error
Code:
Error: Template Directory Not Found!

Could any one suggest what can be wrong, please
Application without p12 extension is working fine.

El Forum

[eluser]philpalmieri[/eluser]
Hi,

it renders the template based on the URI - so, the index.php will screw it up.. add an htaccess file to mask the index.php and it should work for you.

Also, this library has come a long way since this post - i'll be pushing up an update (backwards compatible) this week.

Phil

El Forum

[eluser]philpalmieri[/eluser]
sorry - actually the index.php doesn't matter (just realized that as i saved)... I hadn't tried using it in the application folder, try putting the templates folder right in the root www - and leave the template_dir as /templates/

Phil

El Forum

[eluser]patak[/eluser]
Hi Phil
it works only if templates directory is in the root www and copy of the templates folder in app folder.
Pages: 1 2