is there a way to make Codeigniter use a template for the pages ? |
[eluser]R_Nelson[/eluser]
I was introduced to Rails 3 by a friend and i like it but the syntax drives me nuts. I was told to look into Codeigniter and it seems to have every thing rails has except that the code is NOT DRY (Don't Repeat Yourself. what i'm trying to ask here is in ruby they have a file called application.html.erb witch is basically the the template for your website with a tag in it to display the action from the controller so in other words i don't have to copy code for every page (example <html><title><body> ect..) tags. Is there a way to make this work or could the developers add this into a release?
[eluser]Derek Allard[/eluser]
Welcome to CI R_Nelson. There are a few different ways to do this. Here's a couple examples: 1) From your controller: Code: $this->load->view('html_open'); // this is common 2) From your views Code: <?php $this->load->view('html_open');?> 3) View libraries There are a series of user contributed view libraries available. I've not used any of them, but one I can think of off the top of my head would be Ocular.
[eluser]R_Nelson[/eluser]
not really what i'm looking for let me show you what the ruby file looks like Code: <!DOCTYPE html> the <%= yield %> is what lets the action be displayed or in Codeigniter Function i hope that clears up what i want to do!
[eluser]Derek Allard[/eluser]
This looks to me like a simple view file. I see this is your second post, so forgive me for making assumptions about what you might or might not have had a chance to do. Here's a basic CI controller Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); And the resulting view Code: <!DOCTYPE html> Are we on the same page here?
[eluser]ramm[/eluser]
I'm using Smarty3 with CI http://ilikekillnerds.com/2010/11/using-...i-library/ With the blocks from Smarty, i do something like this: Master Template Code: <!DOCTYPE html> Views Code: {extends file="includes/master.php"} Which is basicly what you are asking for. It can as deep as you want and also you get in the viw all the Smarty functionality like conditionals, loops, cycles, variables with defaul values, etc.
[eluser]R_Nelson[/eluser]
sorry still not on the same page lets say index.php is Code: <p>Hello World! Code: <p>About what ruby dose is uses the page in my example as a template and the Code: <p>Hello World! Code: <p>About That is the best i can enplane it with out giving you a rails 3 lesson i hope that gets us on the same page!
[eluser]R_Nelson[/eluser]
I'm not sure till i try it but ramm may have my answer!
[eluser]ramm[/eluser]
Yep, same thing. My about page will be: Code: {extends file="includes/master.php"} Contact Page Code: {extends file="includes/master.php"} All of them "extending" my master template.
[eluser]Armchair Samurai[/eluser]
You can easily do this with CI. Set up a template page (template.php) in the views folder: Code: <html> Then when you call a view from your controller: Code: $this->load->vars(array(
[eluser]kilishan[/eluser]
[quote author="R_Nelson" date="1299042042"]not really what i'm looking for let me show you what the ruby file looks like Code: <!DOCTYPE html> the <%= yield %> is what lets the action be displayed or in Codeigniter Function i hope that clears up what i want to do![/quote] This is exactly how Ocular works (Thanks for the mention, Derek!). There are a number of other template libraries out there, also, and I think that most of them operate under similar principles. |
Welcome Guest, Not a member yet? Register Sign In |