Re: on-the-fly css/js inclusion with Porto Layout

Jonathan Bowlas <j.bowlas-hclig2XLE9Zaa/[email protected]> Wed, 22 Jun 2011 09:21:05 +0100
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <[email protected]>
Hi Sylvain,

Thanks for the reply, hope you're having a great time in Florence.

Jon

On 21 June 2011 10:59, Sylvain VIOLLON <[email protected]> wrote:
>
> Hello,
>
> On Mon, 20 Jun 2011 11:14 +0100, "Jonathan Bowlas" <j.bowlas-hclig2XLE9Zaa/[email protected]>
> wrote:
>> Hi Devs,
>>
>
> =A0Hello,
>
> =A0Greetings 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=3D"rendered_ucl_content_area
>> context/@@ucl_default_content_area;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 head_content
>> python:'\n'.join(request.other.setdefault('head', []));">
>> =A0<HEAD>
>> =A0 <tal:block content=3D"structure head_content"/>
>> =A0</HEAD>
>> =A0<BODY>
>> =A0 <tal:block metal:define-slot=3D"content" content=3D"structure
>> rendered_ucl_content_area"/>
>> =A0</BODY>
>> </HTML>
>>
>>
>> Then in our code source we do this:
>> <tal:block define=3D'js string:<script type=3D"text/javascript"
>> src=3D"http://www.ucl.ac.uk/js/jquery/ui.tabs.min.js"></script>' />
>>
>> <tal:block define=3D"zz python:request.other.setdefault('head',
>> []).append(js)"/>
>>
>> So what is the recommended approach now?
>>
>
>
> =A0We didn't really changed anything about this in 2.3 (we didn't really
> =A0touch the code sources).
>
> =A0The head_inject should still work, or the solution you proposed should
> =A0work as well.
>
> =A0One of the feature of silva.core.layout is that in your content view,
> =A0the update method of the content view is called before the layout is
> =A0rendered (the template). That might help you as well if you are able
> =A0to collect the needed JS or CSS at that time.
>
> =A0In 3.0, with the changes we made we will be able to add two new
> =A0parameters to code sources that will be a list of CSS and JS to
> =A0include, that will be automatically included in the layout, we now
> =A0have an architecture that let you do that, solving that long standing
> =A0problem.
>
>
> =A0Regards,
>
> =A0Sylvain
>
> --
> Sylvain Viollon -- Infrae
> t +31 10 243 7051 -- http://infrae.com
> Hoevestraat 10 3033GC Rotterdam -- The Netherlands
>



-- =

Jonathan Bowlas
Web Support Officer
Media Services
University College London
Email: j.bowlas-hclig2XLE9Zaa/[email protected]