File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ def patch_template():
3737
3838 original_content = content
3939
40- # Find the endblock and add JavaScript before it
40+ # Find the LAST endblock (content block) and add JavaScript before it
4141 js_code = '''
4242<script>
4343document.addEventListener('DOMContentLoaded', function() {
@@ -54,10 +54,14 @@ def patch_template():
5454
5555{% endblock %}'''
5656
57- if "{% endblock %}" in content :
58- # Replace the last endblock with our JS + endblock
59- content = content .replace ("{% endblock %}" , js_code , 1 )
60- print (" [OK] Added JavaScript for dynamic form switching" )
57+ # Count endblocks - we want to replace the LAST one (content block, not title block)
58+ endblock_count = content .count ("{% endblock %}" )
59+ if endblock_count >= 2 :
60+ # Replace only the last occurrence
61+ # Find the last {% endblock %} and replace it
62+ last_idx = content .rfind ("{% endblock %}" )
63+ content = content [:last_idx ] + js_code
64+ print (f" [OK] Added JavaScript before last endblock (found { endblock_count } endblocks)" )
6165 else :
6266 print (" [WARN] Could not find endblock in template" )
6367 return False
You can’t perform that action at this time.
0 commit comments