Welcome Guest, Not a member yet? Register   Sign In
Best way to avoid duplicating html in views
#12

[eluser]mortifrog[/eluser]
lol - thank you all - I know you all mean well, but your talk of template engines and helpers is melting my brain! (I haven't fully taken on board the purpose of helpers yet) I'm really, really new to OO and CI (as well as being O,S & W as opposed to Y,G & B) so I have a need to keep things really, really simple! I am re-reading this thread and am slowly taking on board some of the stuff that's being said. It's one thing reading the user guide and viewing the tutorials, but for me, it doesn't sick in my head until I start doing it.
For now anyway, I've decided on the template folder approach, as I mean to have interchangable themes. Which I guess means, all my controllers will contain something like the following code.

Code:
<?php
class Modulename extends Controller {
    

    function Modulename()
    {
        parent::Controller();    
    }
    
    function index()
    {    
        $data['page_title'] = 'Site Name - Module Name';
        $data['template'] = 'default';
        $data['masthead'] = $this->load->view("templates/$data['template']/masthead");
        $data['nav'] = $this->load->view("templates/$data['template']/nav");
        $data['content'] = $this->result_of_some_number_crunching_maybe;
        $data['content'] .= $this->load->view('an_extra_view');
        $data['content'] .= $this->load->view('another_view_perhaps');
        $data['footer'] = $this->load->view("templates/$data['template']/footer");
        $this->load->view("templates/$data['template']/index", $data);
    }
} ?>

( or should those references read $this->data['template'] ? )

and my template view will be something like:

Code:
<html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $page_title; ?></title>
<link href="http://<?php echo $_SERVER["HTTP_HOST"]?>/system/application/views/templates/<?php echo $template; ?>/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table class="layout"">
   <tr><td colspan="2">&lt;? php echo $masthead; ?&gt;</td></tr>
   <tr><td>&lt;? php echo $nav; ?&gt;</td><td>&lt;? php echo $content; ?&gt;</td></tr>
   <tr><td colspan="2">&lt;? php echo $footer; ?&gt;</td></tr>
</table>
&lt;/body&gt;&lt;/html>


Thanks again for all your input, it has been most instructive and has helped me to suss out how I'm going to approach this issue.

One last thing on architecture. I tried doing something like:
Code:
$data['content'] = $this->load->controller('some_controller');
- but it didn't work. I thought it would be really useful to be able to load the output of a controller into a string which is in turn passed to a view - but I reckon you all have a better way of doing the same thing. Perhaps I just include and instantiate the other controller?


Messages In This Thread
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:50 AM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 09:31 AM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 10:24 AM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 10:35 AM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 10:46 AM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 01:10 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 01:27 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 05:44 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 06:24 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 06:24 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 06:54 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:04 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:13 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:18 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:19 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:26 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:27 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:29 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:30 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:32 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 08:42 PM
Best way to avoid duplicating html in views - by El Forum - 12-18-2008, 09:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB