XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

the construct {{#each variableName}} doesn't work #141

Closed EGreg closed 8 years ago

EGreg commented 8 years ago

The problem:

A template which includes an {{#each}} construct iterating over some non-empty associative array renders non-empty results in JS handlebars implementations, but renders an empty result in this XaminProject PHP implementation.

Notes:

The problem originates here:

The EachHelper->execute(...) function expects $args to be an array, but then you call $context->get($args) which which expects the first parameter to be a string instead of an array. As a result, $tmp is empty and you do template->discard() which skips over the entire #each construct.

everplays commented 8 years ago

Could you make a snippet to reproduce it?

We even have test coverage for each helper and associative arrays which is passing: https://github.com/XaminProject/handlebars.php/blob/33ec96a1b415f945a5fd833e5234ac1dfbfe08bb/tests/Xamin/HandlebarsTest.php#L242-L246

EGreg commented 8 years ago

My apologies, the issue applied to an earlier version of this library. I pulled the new code and it was fixed.

However, you can see (as a vestige) the mismatch between EachHelper->execute expecting $args to be an array, but then it's actually a string, and calling $context->get($args) with it.

EGreg commented 8 years ago

You can close this issue.