Skip to main content

infrae.layout defines a way to write view that can reuse an existing defined layout in Zope 2. It is similar to megrok.layout, and work the same way, with some additions.

API

You can define a Layout that will be used by a Page. A Page is a view and behave the same way. A page will look for Layout and will render inside it.

Both Page and Layout can be rendered by either a render method, or by an associated template, exactly like a Grok view.

A Layout is found by adapting the request and the content: you can register layouts for your skin, then for a specific content.

If this is not sufficient, a page can use the Grok directive layout to directly specify its type of Layout to use. While defining your layout, you can use the same directive to declare which layout a type belongs to. For instance if you have a skin ICorpSkin:

from infae.layout import layout, Layout, ILayout, Page
from five import grok

from corp.skin import ICorpSkin

grok.skin(ICorpSkin)


class ViewLayout(Layout):

   def render(self):
       return u'View %s' % self.view.content()

class Index(Page):

   def render(self):
       return self.context.title()

Now if on the same content you want an edition layout for instance:

class IEditionLayout(ILayout)
    """Layout to edit content
    """

class EditionLayout(Layout):
    layout(IEditionLayout)

    def render(self):
        return u'Edit %s' % self.view.content()

class Edit(Page):
   layout(IEditionLayout)

   def render(self):
        return self.context.title()

If the above mecanism is not flexible enough for your application, you can write an adapter on the request and your content that provides ILayoutFactory. The adapter will allow you to code the logic to select any layout you want.

CHANGES

1.0 (2010/07/16)

  • Initial release.

Metadata

Release files for infrae.layout 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for infrae.layout 1.0
File Size Uploaded
infrae.layout-1.0.tar.gz 4.7 kB Details

Release files / infrae.layout-1.0.tar.gz

Download URL infrae.layout-1.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1b93705a82d0ac2f3a38b3a35244cac12ff21efe332dd2f16bb647d1b03b9aaa
BLAKE2b-256 checksum
How to use checksums
3631f81e73df81aa4e81c4af66b8467d64127743fbd38accd600c66866995899
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page