Perhaps a unit test is worth a thousand words here. This is the test I expected to pass, which works perfectly fine in JS Handlebars:
def test_each_this_array(self):
template = u"{{#each name}}{{this.[0]}} {{this.[1]}} {{/each}}"
context = {
'name': [
['John', 'Smith'],
['James', 'Joyce']
]
}
result = u"John Smith James Joyce "
self.assertRender(template, context, result)
But instead, it gets rendered as such:
tests/test_acceptance.py:51: in assertRender
self.assertEqual(result, render(template, context, helpers=helpers, partials=partials, **kwargs))
E AssertionError: 'John Smith James Joyce ' != ' '
E - John Smith James Joyce
E +
This is interesting because:
in several other unit tests (eg. test_each, test_each_this, test_context_with_attrs) it seems to successfully test other complex functionalities of #each, where the iterator behaves as an dictionary;
test_GH_158__Using_array_index_twice_breaks_the_template successfully tests the raw arr.[0] functionality of arrays;
in fact, even {{this}} inside the block will render the stringified sublist, eg. ['John', 'Smith'].
But for some reason the engine is having trouble combining these components together to successfully render the above test.
Because of this, I'm having to do a workaround of having the iterator be a dictionary and entering field names to make it work, eg.
Perhaps a unit test is worth a thousand words here. This is the test I expected to pass, which works perfectly fine in JS Handlebars:
But instead, it gets rendered as such:
This is interesting because:
test_each
,test_each_this
,test_context_with_attrs
) it seems to successfully test other complex functionalities of#each
, where the iterator behaves as an dictionary;test_GH_158__Using_array_index_twice_breaks_the_template
successfully tests the rawarr.[0]
functionality of arrays;{{this}}
inside the block will render thestr
ingified sublist, eg.['John', 'Smith']
.But for some reason the engine is having trouble combining these components together to successfully render the above test.
Because of this, I'm having to do a workaround of having the iterator be a dictionary and entering field names to make it work, eg.
which is similar to the behaviour of the
test_list_context
unit test. Any ideas?