Re: Override-layout for Silva 2.1

"Luthiger Stoll Benno" <[email protected]> Fri, 4 Dec 2009 10:06:06 +0100
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <[email protected]>
Dear Sylvain

I guess, this is the Zope3 way to do it.

Thank you, I've two reasonable options now.
Benno


-----Original Message-----
From: Sylvain Viollon [mailto:[email protected]] 
Sent: Freitag, 4. Dezember 2009 10:00
To: Luthiger Stoll Benno
Cc: Silva Developer
Subject: Re: [silva-dev] Override-layout for Silva 2.1

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

_______________________________________________
silva-dev mailing list
silva-dev-IAPFreCvJWM6s/[email protected]
https://lists.infrae.com/mailman/listinfo/silva-dev
smime.p7s (application/x-pkcs7-signature, 3.9 KB) - not displayed