Merge pull request #660 from trheyi/main

refactor: Add conditional hiding of elements in forStatementNode
This commit is contained in:
Max 2024-07-07 02:09:52 +08:00 committed by GitHub
commit 63528c024f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -481,6 +481,24 @@ func (parser *TemplateParser) forStatementNode(sel *goquery.Selection) {
parser.data[indexVarName] = idx
// parser attributes
// Copy the if Attr from the parent node
if ifAttr, exists := new.Attr("s:if"); exists {
res, err := parser.data.Exec(ifAttr)
if err != nil {
parser.errors = append(parser.errors, fmt.Errorf("if statement %v error: %v", parser.sequence, err))
setError(new, err)
parser.show(new)
itemNodes = append(itemNodes, new.Nodes...)
continue
}
if res == true {
parser.hide(new)
continue
}
}
parser.parseElementAttrs(new)
parser.parsed(new)