Welcome Guest, Not a member yet? Register   Sign In
Code Separation
#11

[eluser]gtech[/eluser]
take a look at the template parser class, its aim is to remove the need for php in the view files.

[url="http://ellislab.com/codeigniter/user-guide/libraries/parser.html"]http://ellislab.com/codeigniter/user-guide/libraries/parser.html[/url]

You can even use arrays (or variable pairs as they are labeled in the docs) which you build up in the controller, avoiding the need to use a foreach loop in the view. Its simple to use and the documentation is good and to the point.

example from docs:
view:
Code:
<body>
  <h3>{blog_heading}</h3>
  {blog_entries}
    <h5>{title}</h5>
    <p>{body}</p>
  {/blog_entries}
&lt;/body&gt;
controller:
Code:
$this->load->library('parser');
$data = array(
              'blog_heading' => 'My Blog Heading',
              'blog_entries' => array(
                                      array('title' => 'Title 1', 'body' => 'Body 1'),
                                      array('title' => 'Title 2', 'body' => 'Body 2')
                                      )
            );
// instead of using $this->load->view
$this->parser->parse('blog_template', $data);


Messages In This Thread
Code Separation - by El Forum - 05-29-2008, 08:58 PM
Code Separation - by El Forum - 05-29-2008, 09:14 PM
Code Separation - by El Forum - 05-29-2008, 09:17 PM
Code Separation - by El Forum - 05-29-2008, 09:57 PM
Code Separation - by El Forum - 05-29-2008, 11:14 PM
Code Separation - by El Forum - 05-30-2008, 12:20 AM
Code Separation - by El Forum - 05-30-2008, 12:37 AM
Code Separation - by El Forum - 05-30-2008, 02:31 AM
Code Separation - by El Forum - 05-30-2008, 09:02 AM
Code Separation - by El Forum - 05-30-2008, 07:04 PM
Code Separation - by El Forum - 05-30-2008, 07:10 PM
Code Separation - by El Forum - 05-31-2008, 07:03 PM
Code Separation - by El Forum - 05-31-2008, 09:00 PM
Code Separation - by El Forum - 06-02-2008, 01:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB