Re: Main Layout, Content Provider and Viewlet

Jonathan Bowlas <j.bowlas-hclig2XLE9Zaa/[email protected]> Tue, 7 Jun 2011 12:38:46 +0100
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <[email protected]>
Many thanks Sylvain, I thought it would be something like this. I'll
let you know how I get on.

Cheers

Jon

On 7 June 2011 12:31, Sylvain Viollon <[email protected]> wrote:
> On Tue, 7 Jun 2011 10:19:58 +0100
> Jonathan Bowlas <j.bowlas-hclig2XLE9Zaa/[email protected]> wrote:
>
>> Hi Silva Devs
>>
> =A0Hello,
>
>> Quick question, when developing a new visual theme is it possible to
>> call a function defined within a Main Layout object (i.e. the layout
>> object in the Porto layout called mainlayout) from another
>> ContentProvider or Viewlet page template? If so how would I do this?
>>
>
> =A0If you define a method on your Main layout, you can access it from
> =A0any view, content provider, viewlet or viewlet manager using the
> =A0layout attribute:
>
>
> =A0def update(self):
> =A0 =A0 ...
> =A0 =A0 self.layout.method()
>
>
> =A0Or in a template:
>
> =A0 =A0layout.method() (with Chameleon)
> =A0 =A0layout/method =A0 (with regular templates)
>
>
> =A0Your content provider, view, viewlet must have been created by
> =A0inheriting from one of the base class of silva.core.view.
>
> =A0If you add specific methods to your main layout that are used in your
> =A0layout, don't forget to define them as well on the main layout used
> =A0for errors, like for example :
> =A0(https://dev.infrae.com/browser/silva.core.layout/src/silva/core/layou=
t/porto/porto.py#L57)
>
>> The reason I ask is that we have a NonPublishable SimpleItem
>> (UCLAttributes object) that we use to allow Silva Editors to configure
>> various options within the layout, and rather than having to write a
>> function to call this from every Viewlet and ContentProvider everytime
>> I need a parameter it would be prefereable to call it once globally.
>>
>
> =A0Yes, that would be preferable, and you can use the layout object for
> =A0that, it is partially done for that.
>
> =A0I would even recommend that if you have to compute a setting more
> =A0than two time, you should set it on the layout object, in the update
> =A0method (don't forget to call the update method on the parent class).
>
> =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]