Hello everyone
I wanted to know how does one handle a dynamically generated xml code that is invalid before being proccessed
For example generating a table that displays the information in two cells per row:
<t t-foreach="list" t-as="item">
<tr t-if="item_even">
<td><span t-field="item"></td>
</tr t-if="item_odds>
</t>
This will not work since it's invalid xml because the closing tag has a property and neither will <t t-if="condition"> </tr> </t> since the closing tag is embeded in what the xml sees another tag
Alternatives to this would be looping over grouped items, two by two or how many you want per column, and placing them inside one <tr> in one loop but it's not that elegant
Any way around this?
That is the purpose of the var_last var_first and var_odds var_even (in your case i_last, i_first) to hold index information see: http://odoo-80.readthedocs.org/en/latest/reference/qweb.html#loops The logic of achieving this is not the problem it's just that it does not work in qweb.You need two in the same to make a two columned table. This means you have to open on even and close on odds so the end result is 1 2
Hmm I see I understood your question wrong so I've deleted my reply as it wasn't of any value then. I'm not sure about this though, interesting question. Upvoted it :)
Have a look at this by the way: http://odoo-80.readthedocs.org/en/latest/reference/qweb.html#attributes
My theory (though could very well be wrong) is that the error comes in even before qweb can kick into action.If qweb would come in and resolve the t-tags and loops it would result in valid xml code But before the qweb is parsed it's actually read as standard xml where it sees a closing tag having a attribute which is invalid syntax and stops dead.It does not know that the attribute is actually a qweb condition that will output a empty closing tag which will in the end compose valid XML
IMO looping on a grouped list it's the correct way and a lot more elegant than a conditional closing tag.
is this what you are trying for (last answer) , it works in qweb reports.