CodeIgniter Forums

Full Version: modular views
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]tokyotech[/eluser]
Say I have a nifty module that simulates rounded corners and shadows via HTML/CSS only. What's the best way in CodeIgniter to reuse that module without retyping it all the time? I've thought about creating a module.php in my views folder:

Code:
<div class="module">
    <span>
        <div>
            <span>
                &lt;?= $content ?&gt;
            </span>
        </div>
    </span>
</div>

So whenever I need to use this module from another view, I do:

Code:
$args['content'] = '<b>hello <span class="fart">world</span></b><br />';
$this->load->view('module.php', $args);

But this makes my code less readable because wrapping all the content in the single quotes makes all my HTML red in Dreamweaver. It's also difficult with more complicated multi-line HTML. What's a better way to do this?

El Forum

[eluser]Rob Steele[/eluser]
you could always save the info you want to put in as content as another view. then you could just load it with
Code:
$args['content'] = $this->load->view('content_view','',true); //content_view being your hello world text from above
$this->load->view('module.php',$args);
that way you can edit your view as formatted HTML text in another file.

El Forum

[eluser]Eric Barnes[/eluser]
Or just use a plugin. Something like:

Code:
function my_plugin($content='')
{
  $output = '<yourhtml>'.$content.'</yourhtml>';
}

Then in the view:
&lt;?php echo my_plugin($content); ?&gt;

El Forum

[eluser]Colin Williams[/eluser]
I typically have a formatter helper that does stuff like this. Okay, it never does anything like this because the markup is hideous! Smile Using CSS3 (and filters for IE) is usually better than shitty markup like this.

El Forum

[eluser]tokyotech[/eluser]
I can't use CSS3. Not even FF3 understands all of CSS3. Seems like only Safari 4 can understand most of it. My company is forcing me to be IE6 compliant, so no dice...

I believe Rob Steele's solution is best for MVC. Suzkaw's is doable too, but doesn't it mix control (the function definition itself) with view (the HTML within that function)?

El Forum

[eluser]Eric Barnes[/eluser]
I guess everyone likes to do things their own ways. The reason I suggested a plugin was so later if you ever wanted to go with different html you could just edit the plugin and it would then update everything. But a view is just as good if not better. Smile

El Forum

[eluser]Colin Williams[/eluser]
Maybe my first suggestion was lost. You might end up having several needs for functions that simply markup content in a special way. I would create one format helper (system/application/helpers/format_helper.php) that houses all these types of functions.

El Forum

[eluser]Johan André[/eluser]
[quote author="tokyotech" date="1248994277"]My company is forcing me to be IE6 compliant, so no dice...[/quote]

I would quit that counter-productive job... Smile

El Forum

[eluser]Colin Williams[/eluser]
Also, does "IE6 compliant" mean exact rendering? Are IE6 users going to be hurt if the cheesy rounded-cornered-drop-shadowed effect isn't there? Maybe your company should get with the program. But we're veering off topic...