PDA

View Full Version : {vb:each} loop count...


civil78
05-18-2010, 07:48 AM
Is there any way to find how many loops makes the vb:each in a template?

For example I want to do something like this

<vb:each from="arrayname" key="keyid" value="data">
<vb:if condition="$loops>=4">
Some HTML CODE
<vb:else />
Some Other HTML CODE
</vb:if>
</vb:each>

Thanks

civil78
05-27-2010, 07:29 AM
I know this is the stupid way but it works :)


<vb:if condition="$count = 0"></vb:if>

<vb:each from="array" key="arraykey" value="arrayvalue">

<vb:if condition="$count = $count + 1"></vb:if>

<vb:if condition="$count <= 3">

<!-- YOUR HTML -->

<vb:else />

<!-- YOUR HTML -->

</vb:if>

</vb:each>


Somehow when you put php code inside <vb:if condition="">, the code executed.

If anyone knows other way (exept javascript) please tell me.

smnet
01-17-2011, 12:15 PM
I know this is the stupid way but it works :)


<vb:if condition="$count = 0"></vb:if>

<vb:each from="array" key="arraykey" value="arrayvalue">

<vb:if condition="$count = $count + 1"></vb:if>

<vb:if condition="$count <= 3">

<!-- YOUR HTML -->

<vb:else />

<!-- YOUR HTML -->

</vb:if>

</vb:each>


Somehow when you put php code inside <vb:if condition="">, the code executed.

If anyone knows other way (exept javascript) please tell me.

Edit:.... ok, it works.... it's just+not ideal!!

Retal
01-18-2011, 05:20 PM
You could also use an array with numeric keys, if you can guarantee that the keys are continuous.

$array = ('A', 'B', 'C', 'D');
unset($array[2]);
...
$array = array_values($array);

smnet
01-18-2011, 08:42 PM
It looks like a built in method will be added into a future vBulletin version....

Check this out and don't forget to VOTE
http://tracker.vbulletin.com/browse/VBIV-10883

zlos
01-27-2011, 09:34 AM
Vote added.