Welcome Guest, Not a member yet? Register   Sign In
Very simple template parser (though just a bit better than CI's parser)

Hi guys,

I'm currently in the final stages of building my CMS, fully based on CodeIgniter. The back-end is all done, and now my focus has shifted to the front-end. The actual website itself.

For the front-end I was thinking of using a simple parser class, so users of the CMS an have easy to use pseudo-codes to incorporate in their website templates. I know that it's faster to simply use php codes, but I know my clients would feel way more comfortable using these pseudo-codes (and the client is always right, isn't it? Wink)

So today I started working with CI's parser class, but unfortunately it's not as good as I expected. It works great for the real basic stuff, like inserting a the title, keywords, description, and content of the page. But that's about it. Some thing I came across:

- the class can loop through an array, but doesn't work well if a key in the array also exists as a variable outside the array. This makes sense of course, but reduces the functionality. There should be an easy fix for this, I guess.
- the is no support for doing an if/else
- a for loop with count would be a nice extra feature

Now I've searched the forums, and I know that more people feel the parser class is lacking. I've also seen there are various template classes available on the forum. However, I think none of them are using pseudo-codes.

So now my question is, does anyone know of some good and simple template parsers that I might try to port to CI? I know there is Smarty, but I believe that it is way to complex for my needs. Really, I just want to provide a more simple interface to novice users. As soon as things start to become more complex, we'll be using PHP for that anyway.

Does anyone have some tips for me? A template parser that can do the things I mentioned above?

Thanks in advance, Michiel

tiny but strong found via 19 promising template engines

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)):
<? to start template tag,
?> to end template tag,
to display template variable use echo keyword,

example: <? echo $variable ?>

<? if($variable_to_test): ?> to start conditional,
<? endif; ?> to end conditional,

example: <? if($is_true): ?>

<? foreach($list as $item): ?> to start loop,
<? echo $item ?> inside loop
<? endforeach; ?> to end loop

in the controller...(developer will edit this)
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');
in the view (user will edit this)
    <title><? echo $title ?></title>

<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 />

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


hey I am also facing same situation
But now I came to conclusion that use smarty whenever u need and use default parser class

There is template library available .Please check the following thread

Happy coding :-)

Theme © iAndrew 2016 - Forum software by © MyBB