Opened 8 years ago
Closed 6 years ago
#17251 closed defect (fixed)
[patch][cla] Enable looping over objects with {% for key, value in object %}
Reported by: | hcampbell | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.11 |
Component: | DojoX DTL | Version: | 1.9.0 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
In the following example:
require([ "dojo/dom-construct", "dojox/dtl/Context", "dojox/dtl/_base", "dojox/dtl/dom", "dojox/dtl/tag/logic" ], function(domConstruct, Context, dtl) { var templateString = "" + "<dl>" + " {% for k, v in obj %}" + " <dt>{{ k }}</dt>" + " <dd>{{ v }}</dd>" + " {% endfor %}" + "</dl>", testObj = { "HTML": "HyperText Markup Language", "CSS": "Cascading Stylesheet" }, template; template = new dtl.DomTemplate(templateString); template.render(new Context({"obj": testObj})); domConstruct.place( template.getRootNode(), document.body ); } );
The output is:
<dl> <dt>HyperText Markup Language</dt> <dd>undefined</dd> <dt>Cascading Stylesheet</dt> <dd>undefined</dd> </dl>
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:
<dl> <dt>HTML</dt> <dd>HyperText Markup Language</dd> <dt>CSS</dt> <dd>Cascading Stylesheet</dd> </dl>
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 8 years ago by
comment:2 Changed 6 years ago by
Milestone: | tbd → 1.11 |
---|---|
Priority: | undecided → low |
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 6 years ago by
Owner: | set to dylans <[email protected]…> |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
GH Pull request: https://github.com/dojo/dojox/pull/14