views:

193

answers:

3

What CodeIgniter library can provide this funcionality??

http://media.railscasts.com/videos/008_content_for.mov

It seems so simple on rails but I just cant find a simple way to achieve this on codeigniter.. please help.. I hate having to insert my styles or javascript in the body of the document

+2  A: 

I've achieved this in the past using this Template Library. From the documentation:

The Template library, written for the CodeIgniter PHP-framework, is a wrapper for CI’s View implementation. Template is a reaction to the numerous questions from the CI community regarding how one would display multiple views for one controller, and how to embed “views within views” in a standardized fashion. In addition, Template provides extra Views loading capabilities, the ability to utilize any template parser (like Smarty), and shortcuts for including CSS, JavaScript, and other common elements in your final rendered HTML.

Specifically, check out the library's additional utilities. It allows you to put something like this in your controller:

$this->template->add_js('js/YourJavascriptFile.js');

or

$this->template->add_js('alert("Hello!");', 'embed');

Echo $_scripts in your template (preferably in the <head> section) to utilize JavaScript added via this method.

Similarly, you can do the same with your CSS:

$this->template->add_css('css/main.css');
$this->template->add_css('#logo {display: block}', 'embed', 'print');

..and simply echo $_styles in your <head> section.

Hope that helps.

Colin
Thats pretty good but I wish I could do it in my views..
NachoF
A: 

Check out Twig - it supports "inheritance" (instead of the traditional include header, include footer, etc)

http://www.twig-project.org/

CodeIgniter helper:

http://github.com/jamiepittock/codeigniter-twig or http://github.com/MaherSaif/codeigniter-twig

(haven't tried either, but looks like the latter is a fork w/the latest commits)

bjornbjorn
I have tried this and can confirm that it works http://github.com/MaherSaif/codeigniter-twig
calumbrodie
A: 

Hello,

see an advanced layout library for codeigniter which enables to use as many blocks as we wish on http://newdailyblog.blogspot.com/2010/07/codeigniter-advanced-layout-library.html

Tahsin Hasan
but where can I find the download link?
NachoF