[FIX] web_editor: make sure [data-snippet] is added on internal t-call
Since [1], an attribute is added on all snippet contents, on the main node, to be able to identify them and better support them. This is added thanks to the t-snippet or the t-snippet-call instruction. The problem was this was not working if the first node of the snippet definition is also a t-call to another sub template. This now works. [1]: https://github.com/odoo/odoo/commit/11c60739e4f4379a61581ed179bc7debbb5e91f9 task-2276740 PR #53175
This commit is contained in:
committed by
Laurent Stukkens (LTU)
parent
08ed6afa2a
commit
faf51a373b
@@ -48,15 +48,27 @@ class QWeb(models.AbstractModel):
|
||||
# compile directives
|
||||
|
||||
def _compile_node(self, el, options):
|
||||
if options.get('snippet-key') == options['template']:
|
||||
# Get the path of the template's content
|
||||
path = options['root'].getpath(el).replace('/t', '')
|
||||
# Only append the template key on template's first node.
|
||||
# If it already has a data-snippet it is a saved snippet.
|
||||
# Do not override it.
|
||||
size = len(path.split('/'))
|
||||
if size == 2 and 'data-snippet' not in el.attrib:
|
||||
el.attrib['data-snippet'] = options['template'].split('.', 1)[-1]
|
||||
snippet_key = options.get('snippet-key')
|
||||
if snippet_key == options['template'] \
|
||||
or options.get('snippet-sub-call-key') == options['template']:
|
||||
# Get the path of element to only consider the first node of the
|
||||
# snippet template content (ignoring all ancestors t elements which
|
||||
# are not t-call ones)
|
||||
nb_real_elements_in_hierarchy = 0
|
||||
node = el
|
||||
while node is not None and nb_real_elements_in_hierarchy < 2:
|
||||
if node.tag != 't' or 't-call' in node.attrib:
|
||||
nb_real_elements_in_hierarchy += 1
|
||||
node = node.getparent()
|
||||
if nb_real_elements_in_hierarchy == 1:
|
||||
# The first node might be a call to a sub template
|
||||
sub_call = el.get('t-call')
|
||||
if sub_call:
|
||||
el.set('t-call-options', f"{{'snippet-key': '{snippet_key}', 'snippet-sub-call-key': '{sub_call}'}}")
|
||||
# If it already has a data-snippet it is a saved snippet.
|
||||
# Do not override it.
|
||||
elif 'data-snippet' not in el.attrib:
|
||||
el.attrib['data-snippet'] = snippet_key.split('.', 1)[-1]
|
||||
|
||||
return super()._compile_node(el, options)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user