Python/Mako: Script Tag not showing up from Sub Template when Loaded into Main Template via Ajax Call -
i have 3 level template.
want load dynamically load script tag sub template main template.
template setup:
- a base page headers/scripts
- 2nd level template contains new script tag , loads widget
- 3rd level template contains widget
all i'm trying when 3rd level template loaded, load specific javascript file, don't have heavy filled head tag on base template javascript files may not used.
base template (in head tag):
<script type="text/javascript" src="/assets/scripts/jquery-1.9.1.js"></script> ${next.javascriptincludes()} <script type="text/javascript" src="/assets/scripts/modules/basemodule.js"></script>
2nd template (where script tag is)
##conditional determine if template should inherit base page ##it shouldn't inherit base page if being inserted page using ajax <%! def inherit(context): if context.get('ispage'): return "base_dashboard.mak" else: return none %> <%inherit file="${inherit(context)}"/> <%def name="javascriptincludes()"> <script type="text/javascript" src="/assets/scripts/libs/jquery.maskedinput-1.3.1.min.js"></script> </%def> ## ajax load %if ispage false: blah blah blah shows <script>s</script> <h1>h1 shows up</h1> <p style="color:red;">p tag shows in red</p> <link rel="stylesheet" href="/assets/css/main.css" type="text/css"><- shows <div><script type="text/javascript" src="/assets/scripts/libs/jquery.maskedinput-1.3.1.min.js"></script></div> script tag above missing... %endif <div id="dashboard-profile-container"> <%include file="widgets/profile_widget.mak" /> </div>
3rd template (the widget)
just html
issue: script tag not getting included in header of base template
how handle problem?
my understanding jquery evaluates and strips <script>
tags html fragment loaded ajax, although @ moment can't find proof of in jquery docs:
"html": returns html plain text; included script tags evaluated when inserted in dom.
however, here is in john resig's own words:
when script node inserted document executed (by jquery). avoid re-executing later (this happens lot, turns out) script removed document.
naturally, causes issues when want see contents of script element (as do). think trade-off better in case.
the 1 alternative solution can think of use internal .data() api attach information script element, informing shouldn't executed again @ later time. i'm not sure how unexpected is, though.
so, @ least, jquery used strip <script>
tags in 2009.
to verify can use firebug etc. confirm application indeed returns html blob <script>
tag included - if confirm it's totally not related pyramid of mako
Comments
Post a Comment