Opened 9 years ago

Closed 7 years ago

#17251 closed defect (fixed)

[patch][cla] Enable looping over objects with {% for key, value in object %}

Reported by: hcampbell Owned by: dylans <[email protected]…>
Priority: low Milestone: 1.11
Component: DojoX DTL Version: 1.9.0
Keywords: Cc:
Blocked By: Blocking:


In the following example:

    function(domConstruct, Context, dtl) {
        var templateString = "" +
                "<dl>" + 
                "    {% for k, v in obj %}" +
                "    <dt>{{ k }}</dt>" +
                "    <dd>{{ v }}</dd>" +
                "    {% endfor %}" +
            testObj = {
                "HTML": "HyperText Markup Language",
                "CSS": "Cascading Stylesheet"
        template = new dtl.DomTemplate(templateString);
        template.render(new Context({"obj": testObj}));

The output is:

       <dt>HyperText Markup Language</dt>
       <dt>Cascading Stylesheet</dt>

ForNode? tests for objects and assigns values to the tag arguments. Ideally it would store both key and value, and zip to the supplied arguments, giving the expected result:

       <dd>HyperText Markup Language</dd>
       <dd>Cascading Stylesheet</dd>

The patch to fix the issue is very minor (see attached). This will, however, break existing templates that treats objects as array of values (ie discarding keys). This could be fixed by reversing the order of key/value pairs, but that would break compatibility with the Django template system.

Will reference pull request.

Change History (3)

comment:1 Changed 9 years ago by hcampbell

comment:2 Changed 7 years ago by dylan

Milestone: tbd1.11
Priority: undecidedlow
Summary: Enable looping over objects with {% for key, value in object %}[patch][cla] Enable looping over objects with {% for key, value in object %}

I'll land this for 1.11, and make a note in the release notes.

comment:3 Changed 7 years ago by dylans <[email protected]…>

Owner: set to dylans <[email protected]…>
Resolution: fixed
Status: newclosed

In 1dcf38ea5f15079355ac20df0b372753da9dd6bc/dojox:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.