Welcome Guest, Not a member yet? Register   Sign In
[Sorta solved] Smarty-style {cycle} in parser view file
#1

[eluser]Unknown[/eluser]
Hi all,

I'm trying to replicate what Smarty does with it's {cycle} function in a CI parser view file; namely, flip between a pair of values inside a parser variable pair, but I'm only seeing the first value output over and over again. Can anyone shed some light on what I'm doing wrong, and how to make it flip between "1" and "2" correctly?

Code:
<table>
<tr><th>Extn</th><th>Name</th><th>External(s)</th></tr>
&lt;?php $i=1;?&gt;
{staff}
<tr class="r&lt;?php echo $i; ($i==1?$i++:$i--);?&gt;"><td>{extn}</td><td>{name}</td><td>{externals}</td></tr>
{/staff}
</table>

I've used similar code to this in raw PHP for/foreach loops without problem before now...
#2

[eluser]Unknown[/eluser]
Work-around answer came to me, pass $i from the controller as part of the variable pair, and do the cycling inside the controller, which has worked, but I'd still like to know if this is possible inside the view (despite the fact I'm trying to keep "proper PHP" out of the view - hence using parser).




Theme © iAndrew 2016 - Forum software by © MyBB