Welcome Guest, Not a member yet? Register   Sign In
Template Parser & Associated Questions
#1

[eluser]Gwarrior[/eluser]
I've been using CodeIgniter for well over a year now and somehow I've managed to never notice the built-in Template Parser class. After taking a look at it, it's like Smarty built-in!

So my question is, how many of you swear by it and are there any significant performance drops when using it?

Thanks!
#2

[eluser]rogierb[/eluser]
I've used it on some project when it suited my needs. It is rather lightweight. I didn't notice any mentionable performance drops. Even when parsing 40 or 50 pages (A4 size html for printing) it is still fairly fast.
#3

[eluser]Eric Barnes[/eluser]
I personally would love to use it but for me it never suited a project. If it would just include a simple if / else then I would imagine it would get a lot more use.
#4

[eluser]rogierb[/eluser]
I use if/else statements with the parser.
<code>
if("{some_var}"!="")
</code>

Works like a charm.

And yes, this is php not templating... but hey, it works.
#5

[eluser]Eric Barnes[/eluser]
Very cool. I never thought of doing it that way. Big Grin
#6

[eluser]sophistry[/eluser]
"Smarty was a friend of mine. CI Template Parser, you are no Smarty." - WRT, Sen. Althouse

don't make the mistake thinking CI Template Parser is like Smarty; it's not.

i've used both and now i just use PHP native template style. it's pretty easy - it's even easy to explain. if you use short tags, and you get all of PHP should you need it. with Smarty I was always twisting myself up in smarty-syntax, with the template parser, i was always "prepping" things to get them perfectly arranged in the controller.

here's a rundown of "PHP native template" (copied from this old post http://ellislab.com/forums/viewthread/102566/#517530:
-------------------------------
just turn on short tags and tell the client you found a good template parser. i wrote the documentation for you below. :-)

the syntax is very simple (and supports what you want - if and foreach)):
&lt;? to start template tag,
?&gt; to end template tag,
to display template variable use echo keyword,

example: &lt;? echo $variable ?&gt;

&lt;? if($variable_to_test): ?&gt; to start conditional,
&lt;? endif; ?&gt; to end conditional,

example: &lt;? if($is_true): ?&gt;

&lt;? foreach($list as $item): ?&gt; to start loop,
&lt;? echo $item ?&gt; inside loop
&lt;? endforeach; ?&gt; to end loop

in the controller...(developer will edit this)
Code:
function template()
    {
        $d['title']='this is a title';
        $d['heading1']='this is a heading one';
        $d['variable']='this is a variable.';
        $d['rand_variable']='this is a variable to show at random.';
        $d['show'] = rand(0,1);
        $d['list'] = array('list item 1', 'list item 2', 'list item 3');
        $this->load->view('tester',$d);
    }
in the view (user will edit this)
Code:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;? echo $title ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h1>&lt;? echo $heading1 ?&gt;</h1>

&lt;? echo $variable ?&gt;<br />

&lt;? if($show): ?&gt;
    &lt;? echo $rand_variable ?&gt;
&lt;? else: ?&gt;
    This will print if the random variable is not shown on this page load - refresh page.
&lt;? endif; ?&gt;

<br />

<ol>
&lt;? foreach($list as $item): ?&gt;
    <li>&lt;? echo $item ?&gt;</li>
&lt;? endforeach; ?&gt;
</ol>

&lt;/body&gt;
&lt;/html&gt;

EDIT: you could even do it with short tags
Code:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h1>&lt;?=$heading1?&gt;</h1>

&lt;?=$variable?&gt;<br />

&lt;? if($show): ?&gt;
    &lt;?=$rand_variable?&gt;
&lt;? else: ?&gt;
    This will print if the random variable is not shown on this page load - refresh page.
&lt;? endif; ?&gt;

<br />

<ol>
&lt;? foreach($list as $item): ?&gt;
    <li>&lt;?=$item?&gt;</li>
&lt;? endforeach; ?&gt;
</ol>

&lt;/body&gt;
&lt;/html&gt;




Theme © iAndrew 2016 - Forum software by © MyBB