[silva-dev] Main Layout, Content Provider and Viewlet
Kit BLAKE
kitblake at infrae.com
Tue Jun 7 19:43:27 CEST 2011
Thanks for sending that code. It's exactly what people want to find.
Kit
On 7 Jun 2011, at 16:53, Jonathan Bowlas wrote:
> Ok, I did this, which worked:
>
> class MainLayout(porto.MainLayout):
>
> grok.template('mainucllayout')
>
> def attobject(self):
> return getattr(self.context, 'uclattributes', None)
>
> class MainErrorLayout(porto.MainErrorLayout):
>
> def attobject(self):
> return getattr(self.context, 'uclattributes', None)
>
> And in my template:
>
> tal:define="atts layout/attobject"
>
> Much appreciated.
>
> Jon
>
>
>
> On 7 June 2011 12:38, Jonathan Bowlas <j.bowlas at ucl.ac.uk> wrote:
>> 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 <sylvain at infrae.com> wrote:
>>> On Tue, 7 Jun 2011 10:19:58 +0100
>>> Jonathan Bowlas <j.bowlas at ucl.ac.uk> wrote:
>>>
>>>> Hi Silva Devs
>>>>
>>> Hello,
>>>
>>>> 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?
>>>>
>>>
>>> If you define a method on your Main layout, you can access it from
>>> any view, content provider, viewlet or viewlet manager using the
>>> layout attribute:
>>>
>>>
>>> def update(self):
>>> ...
>>> self.layout.method()
>>>
>>>
>>> Or in a template:
>>>
>>> layout.method() (with Chameleon)
>>> layout/method (with regular templates)
>>>
>>>
>>> Your content provider, view, viewlet must have been created by
>>> inheriting from one of the base class of silva.core.view.
>>>
>>> If you add specific methods to your main layout that are used in
>>> your
>>> layout, don't forget to define them as well on the main layout used
>>> for errors, like for example :
>>> (https://dev.infrae.com/browser/silva.core.layout/src/silva/core/layout/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.
>>>>
>>>
>>> Yes, that would be preferable, and you can use the layout object
>>> for
>>> that, it is partially done for that.
>>>
>>> I would even recommend that if you have to compute a setting more
>>> than two time, you should set it on the layout object, in the
>>> update
>>> method (don't forget to call the update method on the parent
>>> class).
>>>
>>> Regards,
>>>
>>> Sylvain,
>>>
>>>
>>>
>>>
>>> --
>>> 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 at ucl.ac.uk
>>
>
>
>
> --
> Jonathan Bowlas
> Web Support Officer
> Media Services
> University College London
> Email: j.bowlas at ucl.ac.uk
> _______________________________________________
> silva-dev mailing list
> silva-dev at lists.infrae.com
> https://lists.infrae.com/mailman/listinfo/silva-dev
--
Kit BLAKE · Infrae · http://infrae.com/ + 31 10 243 7051
More information about the silva-dev
mailing list