Skip to content

Commit dbdaf47

Browse files
authoredNov 7, 2023
Merge pull request #879 from antoineveldhoven/colon-array-element
Allow colon inside Twig.expression.type.key.brackets.
2 parents f2bd93e + 062e966 commit dbdaf47

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎src/twig.expression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ module.exports = function (Twig) {
913913
},
914914
{
915915
type: Twig.expression.type.key.brackets,
916-
regex: /^\[([^\]:]*)\]/,
916+
regex: /^\[([^\]]*)\]/,
917917
next: Twig.expression.set.operationsExtended.concat([
918918
Twig.expression.type.parameter.start
919919
]),

‎test/test.expressions.js

+5
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ describe('Twig.js Expressions ->', function () {
332332
const testTemplate = twig({data: '{% if a is defined and a %}true{% else %}false{% endif %}'});
333333
testTemplate.render({a: ['value']}).should.equal('true');
334334
});
335+
336+
it('should be able to access array elements with colons', function () {
337+
const testTemplate = twig({data: '{% for d in data["test:element"] %}{{ d.id }}{% endfor %}'});
338+
testTemplate.render({data: {'test:element':[{'id': 100}]}}).should.equal('100');
339+
});
335340
});
336341

337342
describe('Other Operators ->', function () {

0 commit comments

Comments
 (0)
Please sign in to comment.