Very simple template parser (though just a bit better than CI's parser)

#3
[eluser]sophistry[/eluser]
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)
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:
<html>
<head>
    <title><? echo $title ?></title>
</head>
<body>

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


Messages In This Thread
Very simple template parser (though just a bit better than CI's parser) - by El Forum - 01-16-2009, 03:28 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.