I used PHP years ago but have since been developing in C#/VB.Net.
In ASP.Net MVC 2, you can provide a master page which defines content areas eg:
<html>
<head>
<title>Overshare | <?=$Title?></title>
<ContentArea name="Head"/>
</head>
<body>
<ContentArea name="Body"/>
</body>
</html>
Your view would then have something like:
<Content name="Head">
<!-- Some Head Content -->
</Content>
<Content name="Body">
<h1>Some Body Here</h1>
</Content>
I don’t seem to be able to emulate the same functionality with Code Igniter. The options seem to be:
- manually pre-set some associative array of variables (eg in the controller) and then simply substitute the values into a template file – This is a lot of code to repeat in each view and doesn’t belong in the controller. It also means it’s a real pain to put large bodies of html into one of the
ContentAreas– It’s either string concatenation or something equally nasty with almost no chance of HTML intellisense in any IDE. - Use a templating library – I haven’t found one which doesn’t fundamentally work as described above
Now, I haven’t used CodeIgniter before and am about to start a large PHP project so want to make sure it’s the correct tool before actually starting work. Am I missing something obvious or is this templating functionality difficult to replicate?
Edit: Libraries tested:
I ended up creating 3 files which represented the following
OpenHeader:
OpenBody:
Close:
And then modified my views to include these three at the appropriate time.
It’s inelegant but flexible and powerful so it’ll do for now – especially since I can pass varuables eg Page title into the files during the include if I use the CodeIgniter view engine to retrieve them