XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

Each special variables #51

Closed JustBlackBird closed 10 years ago

JustBlackBird commented 10 years ago

About the PR. There was a difference in "@index" and "@key" special variables in "#each" helper between PHP and JavaScript version of Handlebars. JS version provides "@index" for all containers (both objects and arrays) and "@key" for objects. Here is a proof fiddle: http://jsfiddle.net/5e7vS/1/. At the same time PHP version provides either "@key" or "@index" depending on a container type.

Also, as wrote in #46 there was no "@first"/"@last" elements in "#each" helper.

About implementation. I've assumed that only PHP arrays with sequential numeric keys are equivalent to JavaScript arrays. For such "arrays" "@index", "@first" and "@last" special variables are available in "#each" helper.

On the other hand, all other arrays and instances of \Traversable are treated as JavaScript objects. For such "objects" "@index", "@key" and "@first" special variables are available in "#each" helper.

everplays commented 10 years ago

thanks @JustBlackBird.

JustBlackBird commented 10 years ago

You are welcome.

nonnenmacher commented 10 years ago

Thanks a lot !