Opened 10 years ago

Closed 10 years ago

#8291 closed defect (fixed)

dojox.dtl - Template inheritance ('extends' tag) broken in trunk

Reported by: rsaccon Owned by: Neil Roberts
Priority: high Milestone: 1.3
Component: DojoX DTL Version: 1.2.3
Keywords: dojox, dtl, extends Cc:
Blocked By: Blocking:

Description

When I updated from a dojo version < 1.2, I realized that the 'extends' tag does not work anymore properly. I have observed the following behavior: if the child template (the one 'extending' the parent template) contains just text or a single DOM node, everything is fine. If it contains a more complex DOM node structure, only the first node gets rendered at the first rendering cycle (in a HtmlTemplated?.js widget), at successive rendering cycles the whole node-list gets rendered but with wrong order of nodes.

Unfortunately the test-suite does only contain an empty dummy test for the 'extends' tag. Following are two simple test cases (for copy-pasting into 'dojox.dtl.tests.html.tag') illustrating the problem for the first rendering cycle.

		function test_tag_extendOk(t){
			var dd = dojox.dtl;

			var context = new dd.Context({
				base: dojo.moduleUrl("dojox.dtl.tests.templates", "base.html")
			});

			var template = new dd.HtmlTemplate("{% extends base %}{% block base %}<p>1</p>{% endblock %}");
			t.is("<div>BaseBefore<p>1</p>BaseAfter</div>", dd.tests.html.util.render(template, context));
		},
		function test_tag_extendFailure(t){
			var dd = dojox.dtl;

			var context = new dd.Context({
				base: dojo.moduleUrl("dojox.dtl.tests.templates", "base.html")
			});

			var template = new dd.HtmlTemplate("{% extends base %}{% block base %}<p>1</p><p>2</p>{% endblock %}");
			t.is("<div>BaseBefore<p>1</p><p>2</p>BaseAfter</div>", dd.tests.html.util.render(template, context));
		},

feel free to contact me anytime at rsaccon at gmail, if further information is required or if I can help to implement a fix.

Attachments (1)

base.html (63 bytes) - added by rsaccon 10 years ago.
additional base template used in the test case

Download all attachments as: .zip

Change History (8)

Changed 10 years ago by rsaccon

Attachment: base.html added

additional base template used in the test case

comment:1 Changed 10 years ago by Adam Peller

Owner: changed from Adam Peller to Neil Roberts

comment:2 Changed 10 years ago by Adam Peller

Component: DojoxDojoX DTL

comment:3 Changed 10 years ago by Neil Roberts

Resolution: fixed
Status: newclosed

comment:4 Changed 10 years ago by rsaccon

Resolution: fixed
Status: closedreopened

unfortunately the problem is not completely fixed yet. In the test-case the block which extends the base template contains two nodes and the test passes. But if I add more nodes, then the old misbehavior comes back. In the example below I have three domNodes inside the block which I extend the base template, now at first rendering cycle, the last node is missing and at folowing render cycles, the ordering is wrong (1-3-2 instead of 1-2-3)

  _AssertFailure: doh._AssertFailure: assertEqual() failed:
 	expected
		<div>BaseBefore<p>1</p><p>2</p><p>3</p>BaseAfter</div>
	but got
		<div>BaseBefore<p>1</p><p>2</p>BaseAfter</div>

: assertEqual() failed:
	expected
		<div>BaseBefore<p>1</p><p>2</p><p>3</p>BaseAfter</div>
	but got
		<div>BaseBefore<p>1</p><p>2</p>BaseAfter</div>

 doh._AssertFailure: assertEqual() failed:
     expected
		<div>BaseBefore<p>1</p><p>2</p><p>3</p>BaseAfter</div>
	but got
		<div>BaseBefore<p>1</p><p>2</p>BaseAfter</div>

     ERROR IN:
 		 function test_tag_extend(t) 
{
  var dd = dojox.dtl;
  var context = new dd.Context({ "base": dojo.moduleUrl("dojox.dtl.tests.templates", "base.html") });
  var template = new dd.HtmlTemplate("{% extends base %}{% block base %}<p>1</p><p>2</p><p>3</p>{% endblock %}");
  t.is("<div>BaseBefore<p>1</p><p>2</p><p>3</p>BaseAfter</div>", dd.tests.html.util.render(template, context));
}
 FAILED test: test_tag_extend 6 ms

comment:5 Changed 10 years ago by Neil Roberts

Resolution: fixed
Status: reopenedclosed

(In [16110]) Fixes #8291. Good catch on improving the test. Parent is now reassigned properly no matter the number of nodes. !strict

comment:6 Changed 10 years ago by rsaccon

Resolution: fixed
Status: closedreopened

Unfortunately I managed again to produce a failing test-case. If I a put a nested node structure into the block I am extending, then again I get at first rendering cycle not all nodes and at following rendering cycles wrong order and wring nesting. Below a example of such a block:

{% extends base %}
{% block base %}
<p>1</p>
<ul>
  	<li>1a</li>
	<li>1b</li>
	<li>1c</li>
</ul>
<p>2</p> 
<ul>
  	<li>2a</li>
	<li>2b</li>
	<li>2c</li>
</ul>
<p>3</p>
<ul>
  	<li>3a</li>
	<li>3b</li>
	<li>3c</li>
</ul>
<p>4</p>
<ul>
  	<li>4a</li>
	<li>4b</li>
	<li>4c</li>
</ul>
<p>5</p>
{% endblock  %}

comment:7 Changed 10 years ago by Neil Roberts

Resolution: fixed
Status: reopenedclosed

(In [16114]) Fixes #8291 (hopefully). Do a much more accurate top-level parent reset. Makes code smaller too. !strict

Note: See TracTickets for help on using tickets.