Re: on-the-fly css/js inclusion with Porto Layout
"Sylvain VIOLLON" <[email protected]> Tue, 21 Jun 2011 11:59:47 +0200
| Newsgroups | gmane.comp.web.zope.silva.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello, On Mon, 20 Jun 2011 11:14 +0100, "Jonathan Bowlas" <j.bowlas-hclig2XLE9Zaa/[email protected]> wrote: > Hi Devs, > Hello, Greetings from EuroPython, under the sun of Italia. > Could someone please explain how I could utilise the 'Injector for > on-the-fly css/js inclusion' in the porto mainlayout.pt to inject > scripts and stylesheets from a code source? This doesn't appear to be > documented anywhere. > > When using SilvaLayout we did the following: > > <HTML tal:define="rendered_ucl_content_area > context/@@ucl_default_content_area; > head_content > python:'\n'.join(request.other.setdefault('head', []));"> > <HEAD> > <tal:block content="structure head_content"/> > </HEAD> > <BODY> > <tal:block metal:define-slot="content" content="structure > rendered_ucl_content_area"/> > </BODY> > </HTML> > > > Then in our code source we do this: > <tal:block define='js string:<script type="text/javascript" > src="http://www.ucl.ac.uk/js/jquery/ui.tabs.min.js"></script>' /> > > <tal:block define="zz python:request.other.setdefault('head', > []).append(js)"/> > > So what is the recommended approach now? > We didn't really changed anything about this in 2.3 (we didn't really touch the code sources). The head_inject should still work, or the solution you proposed should work as well. One of the feature of silva.core.layout is that in your content view, the update method of the content view is called before the layout is rendered (the template). That might help you as well if you are able to collect the needed JS or CSS at that time. In 3.0, with the changes we made we will be able to add two new parameters to code sources that will be a list of CSS and JS to include, that will be automatically included in the layout, we now have an architecture that let you do that, solving that long standing problem. Regards, Sylvain -- Sylvain Viollon -- Infrae t +31 10 243 7051 -- http://infrae.com Hoevestraat 10 3033GC Rotterdam -- The Netherlands