Hello,
I'm using wavesurfer in a site, so have included it at the bottom of layout.html.
<!-- The javascript -->
<script src="{{=URL('static','js/bootstrap.min.js')}}"></script>
<script src="{{=URL('static','js/web2py-bootstrap3.js')}}"></script>
But then one of my views has javascript code to setup a wavesurfer player. This is currently included at the bottom of the view - note that it includes some web2py expressions to populate variables.
<!-- The javascript =============================== -->
<script type="text/javascript">
var wavesurfer = WaveSurfer.create({
container: '#waveform',
});
wavesurfer.load("{{=URL('static', record.static_filepath)}}");
</script>
It doesn't work, but I think for the simple reason that the script in the view is included ahead of the scripts loaded in the layout (the contents of the view all gets stuck inside {{include}} in the layout, right?). If I put copy those layout javascript lines into the view ahead of my local inline script, then it works. However, I don't think I want pages loading the same javascript twice, so now I have to load those javascript files at the end of every view.
Is there a canonical way to handle this? Do blocks allow me to split insert the contents of a view into different parts of the layout? Or am I better off turning the script into a static JS file that all pages load and adding a simple order-agnostic javascript to define the java variables.
Many thanks,
David