Ha, I was right: > Do blocks allow me to split insert the contents of a view into different > parts of the layout?
It’s a good thing that it is a really complex mechanism, so I don’t look like a total idiot ;-) Many thanks - fantastic to get such a quick answer. Cheers, David > On 31 Mar 2017, at 15:56, Carlos Costa <yamandu.co...@gmail.com> wrote: > > A proper way to do this is to put the page javascript in the page_js block > It is the declared in the default layout.html. > > To use it just do this in your view > > {{block page_js}} > ...put your js here... > {{end page_js}} > > This way it will be inserted in the right place into the rendered page. > > > 2017-03-31 11:45 GMT-03:00 David Orme <david.o...@gmail.com > <mailto:david.o...@gmail.com>>: > 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> > <script > src="http://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/1.0.52/wavesurfer.min.js > > <http://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/1.0.52/wavesurfer.min.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 > > -- > Resources: > - http://web2py.com <http://web2py.com/> > - http://web2py.com/book <http://web2py.com/book> (Documentation) > - http://github.com/web2py/web2py <http://github.com/web2py/web2py> (Source > code) > - https://code.google.com/p/web2py/issues/list > <https://code.google.com/p/web2py/issues/list> (Report Issues) > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com > <mailto:web2py+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. > > > > -- > > > Carlos J. Costa > Cientista da Computação | BS Computer Science > Esp. Gestão em Telecom | PgC Telecom Mangement > <º))>< > > -- > Resources: > - http://web2py.com <http://web2py.com/> > - http://web2py.com/book <http://web2py.com/book> (Documentation) > - http://github.com/web2py/web2py <http://github.com/web2py/web2py> (Source > code) > - https://code.google.com/p/web2py/issues/list > <https://code.google.com/p/web2py/issues/list> (Report Issues) > --- > You received this message because you are subscribed to a topic in the Google > Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/k0xtY1Jz9-s/unsubscribe > <https://groups.google.com/d/topic/web2py/k0xtY1Jz9-s/unsubscribe>. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com > <mailto:web2py+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.