[silva-dev] Main Layout, Content Provider and Viewlet

Sylvain Viollon sylvain at infrae.com
Tue Jun 7 13:31:00 CEST 2011


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


More information about the silva-dev mailing list