[IMP] qweb: Allow to propagate value to variables outside the loop.
If the variable was existing outside the context of the ``foreach``, the value is copied at the end of the foreach into the global context. Fix #4461 - Q74531 - Q71486 - Q71675
This commit is contained in:
parent
67443b5b17
commit
4a698da8b3
|
@ -187,6 +187,10 @@ var QWeb2 = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_.each(Object.keys(old_dict), function(z) {
|
||||||
|
old_dict[z] = new_dict[z];
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.exception("No enumerator given to foreach", context);
|
this.exception("No enumerator given to foreach", context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,26 @@ variables for various data points:
|
||||||
a boolean flag indicating that the current iteration round is on an odd
|
a boolean flag indicating that the current iteration round is on an odd
|
||||||
index
|
index
|
||||||
|
|
||||||
|
|
||||||
|
These extra variables provided and all new variables created into the
|
||||||
|
``foreach`` are only available in the scope of the``foreach``. If the
|
||||||
|
variable exists outside the context of the ``foreach``, the value is copied
|
||||||
|
at the end of the foreach into the global context.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
<t t-set="existing_variable" t-value="False"/>
|
||||||
|
<!-- existing_variable now False -->
|
||||||
|
|
||||||
|
<p t-foreach="[1, 2, 3]" t-as="i">
|
||||||
|
<t t-set="existing_variable" t-value="True"/>
|
||||||
|
<t t-set="new_variable" t-value="True"/>
|
||||||
|
<!-- existing_variable and new_variable now True -->
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- existing_variable always True -->
|
||||||
|
<!-- new_variable undefined -->
|
||||||
|
|
||||||
.. _reference/qweb/attributes:
|
.. _reference/qweb/attributes:
|
||||||
|
|
||||||
attributes
|
attributes
|
||||||
|
|
|
@ -414,6 +414,10 @@ class QWeb(orm.AbstractModel):
|
||||||
'%s_odd' % varname: False,
|
'%s_odd' % varname: False,
|
||||||
})
|
})
|
||||||
ru.append(self.render_element(element, template_attributes, generated_attributes, copy_qwebcontext))
|
ru.append(self.render_element(element, template_attributes, generated_attributes, copy_qwebcontext))
|
||||||
|
|
||||||
|
for k in qwebcontext.keys():
|
||||||
|
qwebcontext[k] = copy_qwebcontext[k]
|
||||||
|
|
||||||
return "".join(ru)
|
return "".join(ru)
|
||||||
|
|
||||||
def render_tag_if(self, element, template_attributes, generated_attributes, qwebcontext):
|
def render_tag_if(self, element, template_attributes, generated_attributes, qwebcontext):
|
||||||
|
|
Loading…
Reference in New Issue