CodeIgniter Forums
[Solved] Where factorize HTML code ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [Solved] Where factorize HTML code ? (/showthread.php?tid=7135)



[Solved] Where factorize HTML code ? - El Forum - 03-26-2008

[eluser]Kromack[/eluser]
Hello everyone,

I'm using CI to remake my own little "CMS", I coded it in a two layers way, just with a template engine, some files likes controllers and libraries that look like models.

I used to call a function in my controllers that produce a box in a string way :

Code:
//We make a long string with all the code HTML of boxes
$box = makeBox($title, $content);
$box .= makeBox($anotherTitle, $anotherContent);

//We inject this code
$template->parse('myBoxes', $box);

I'm a little confused because, with CI i think I should write directly all the HTML code of all my boxes in a view.

Ok, but I have 10 boxes on a same page, it make a big view file and duplicated code... Also, instead of call one function, I have to copy / paste an entire bloc of HTML (corresponding to the box).

So my question is :

How to simplify my boxes management ?

Using an custom helper ? I have tryed but, controllers have to work with HTML (not good for MVC xD...)

Giving data to the views in order to they call an helper (Hum many PHP in views... not good for MVC xD...)

I hope I am clear, thank you for your help Smile


[Solved] Where factorize HTML code ? - El Forum - 03-26-2008

[eluser]xwero[/eluser]
I'm not sure what you exactly want but the way i would do the thing you want is to create 2 views
Code:
<!-- views/box.php -->
<div class="box">
<h1>&lt;?php echo $box->title; ?&gt;</h1>
&lt;?php echo $box->content; ?&gt;
</div>
&lt;!-- views/boxes.php --&gt;
&lt;?php foreach($boxes as $box){ echo $box; } ?&gt;
And in the controller
Code:
$boxes = array();
foreach($query as $row)
{
    $boxes[] = $this->load->view('box',array('box'=>$row),TRUE);
}
$this->load->view('boxes',array('boxes'=>$boxes));
This way the view files can be used for more than only displaying boxes. I hope this helps.


[Solved] Where factorize HTML code ? - El Forum - 03-26-2008

[eluser]Kromack[/eluser]
What an elegant way !

Thank you very much xwero it is exactly the kind of solution I looked for !


[Solved] Where factorize HTML code ? - El Forum - 09-14-2008

[eluser]fouadami[/eluser]
Well yes, the 3rd argument of view method should be mentioned in the user documents section too!


[Solved] Where factorize HTML code ? - El Forum - 09-14-2008

[eluser]Derek Allard[/eluser]
Quote:Well yes, the 3rd argument of view method should be mentioned in the user documents section too!
Its noted on the loader page, but I've just also added it to the view page. I'll be part of the next release.


[Solved] Where factorize HTML code ? - El Forum - 09-14-2008

[eluser]Pascal Kriete[/eluser]
[quote author="Derek Allard" date="1221417381"]I'll be part of the next release.[/quote]
Is this opt-in or opt-out?


[Solved] Where factorize HTML code ? - El Forum - 09-14-2008

[eluser]wiredesignz[/eluser]
[quote author="Derek Allard" date="1221417381"]I'll be part of the next release.[/quote]

Sweet, I always wanted my very own copy of Derek Allard. :lol:


[Solved] Where factorize HTML code ? - El Forum - 09-14-2008

[eluser]Derek Allard[/eluser]
LOL!

I'll be auto-loaded and without the derekallard.php library CI simply won't work!


[Solved] Where factorize HTML code ? - El Forum - 09-16-2008

[eluser]Crimp[/eluser]
Wow, that's Matrix-style dedication: a merger of flesh and framework coming to CI in the new D n' A 2.0 feature.


[Solved] Where factorize HTML code ? - El Forum - 09-16-2008

[eluser]drewbee[/eluser]
[quote author="Crimp" date="1221567067"]Wow, that's Matrix-style dedication: a merger of flesh and framework coming to CI in the new D n' A 2.0 feature.[/quote]


So what your saying is I can dodge bullets or something?

When were finished, you won't have to.

:coolgrin: