feulf / raintpl3

The easiest Template Engine for PHP
https://feulf.github.io/raintpl
258 stars 57 forks source link

Feature Wish: isLast and isFirst loop element variable #131

Open dhardtke opened 10 years ago

dhardtke commented 10 years ago

Hey,

I would like to have the possiblity to detect if I am in the last element of the loop or the first..

Currently I'm realizing it like this:

{if="$counter != count($breadcrumbs)-1"}

which means IF currentCounterValue is not reached

hope you can make something like this possible.

Greets

feulf commented 10 years ago

I don't want to add more tags. I'm thinking instead to implement a custom tags feature that works with autoload.

So you'll be able to create a {isLast} tag yourself.

dhardtke commented 10 years ago

I meant something like a variable for that purpose - like counter but just as boolean instead of int.

feulf commented 10 years ago

I see your point. Well you can still do something like this:

{$isLast="$counter = count($breadcrumbs)-1"}

and than use {$isLast}

{if="$isLast"} ... {/if}

I'll consider to add that in the loop anyway, thanks for your suggestion.