Re: Override-layout for Silva 2.1

Sylvain Viollon <[email protected]> Fri, 4 Dec 2009 10:00:29 +0100
Newsgroups gmane.comp.web.zope.silva.devel
Organization Infrae
Message-ID <[email protected]>
On Fri, 4 Dec 2009 09:29:19 +0100
"Luthiger Stoll  Benno" <[email protected]> wrote:

> Hello all
> 

  Hello,

> Is there no more help available from the infrae pros concerning my
> question? Just a little tip, maybe.
> 

  I didn't tried it, but I think this should work:

  1. Create a python class, on the filesystem, in a py file (let's
     called it views.py) for your container:

     from Products.SilvaLayout.browser.silvaviews import Container

     class TranslatedContainer(Container):

        def context_or_default(self):
            # 1. figure out the language.
            language = self.request.cookies.get('silva_language', 'en')
            language = language.upper()
            container = self.context.aq_inner
            # 2. Lookup the index document
            index = getattr(container, 'index_' + language, None)
            if index is None:
               # Try to fallback to default silva index documents
               index = getattr(container, 'index', None)
            return index


   2. After in your ZCML, when you declare the 'container' template,
      use your new class:

      <browser:page
          name="index.html"
          for="Products.Silva.interfaces.IContainer"
          class=".views.TranslatedContainer"
          template="maintemplate.pt"
          permission="zope2.View"
          layer=".skin.IYourLayer"
          />

      Of course we assumed here that the python file views.py is in the
      same directory than the configure.zcml file.


    3. Restart, 


    Regards,

    Sylvain,


Note: SilvaLayout is deprecated in favor of silva.core.layout. It will
still exists in 2.2, but will be removed one day.

-- 
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands