Skip to content

Commit

Permalink
Merge pull request #879 from antoineveldhoven/colon-array-element
Browse files Browse the repository at this point in the history
Allow colon inside Twig.expression.type.key.brackets.
  • Loading branch information
willrowe authored Nov 7, 2023
2 parents f2bd93e + 062e966 commit dbdaf47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/twig.expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ module.exports = function (Twig) {
},
{
type: Twig.expression.type.key.brackets,
regex: /^\[([^\]:]*)\]/,
regex: /^\[([^\]]*)\]/,
next: Twig.expression.set.operationsExtended.concat([
Twig.expression.type.parameter.start
]),
Expand Down
5 changes: 5 additions & 0 deletions test/test.expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ describe('Twig.js Expressions ->', function () {
const testTemplate = twig({data: '{% if a is defined and a %}true{% else %}false{% endif %}'});
testTemplate.render({a: ['value']}).should.equal('true');
});

it('should be able to access array elements with colons', function () {
const testTemplate = twig({data: '{% for d in data["test:element"] %}{{ d.id }}{% endfor %}'});
testTemplate.render({data: {'test:element':[{'id': 100}]}}).should.equal('100');
});
});

describe('Other Operators ->', function () {
Expand Down

0 comments on commit dbdaf47

Please sign in to comment.