I have the following jQuery call that correctly creates and loads a DataTable on my page. This only works, however, when this script is part of the HTML file because my sAjaxSource URL is composed using a template substitution value: ${company.name}.
When I move this code to a separate .js file it still runs and creates the DataTable. Since the template substitution never runs on the include .js file, however, the sAjaxSource is not set and the table doesn't load properly.
What is the proper way of handling this? Do I have to include at least this javascript function in the HTML file itself?
function() {
$('#fund-contacts-table').dataTable( {bFilter: false,
bInfo: false,
bJQueryUI: true,
bPaginate: false,
bStateSave: false,
bSort: false,
bAutoWidth: false,
aoColumns: [ {"sTitle" : "Date", "sWidth" : "20%"}, {"sTitle" : "Our Team", "sWidth" : "20%"}, {"sTitle" : "Client Team", "sWidth" : "20%"}, {"sTitle" : "Note", "sWidth" : "40%"} ],
sAjaxSource: "/contact/${company.name}/"} );
});
My best answer so far (but I'll leave the question open to see if someone can really solve it):
Instead of including my script file using <script src=. . . />
in my HTML, I'm including it this way:
<script>
<%include file="../js/fund_page.js" />
</script>
where %include
is a Mako directive that reads the specified file, performs template processing on it, and includes it in the HTML file. It appears to be intended for HTML fragments, but works here too.
Unfortunately, that means that I'll lose the optimization to not download the script file if it hasn't changed. On the other hand, the reason this is an issue is that the script file does change from page to page, so that may not be a major loss.