kotti.views.slots

This module allows add-ons to assign views to slots defined in the overall page. In other systems, these are called portlets or viewlets.

A simple example that’ll include the output of the ‘hello_world’ view in in the left column of every page:

from kotti.views.slots import assign_slot
assign_slot('hello_world', 'left')

It is also possible to pass parameters to the view:

assign_slot('last_tweets', 'right', params=dict(user='foo'))

In the view you can get the slot in that the view is rendered from the request:

@view_config(name='last_tweets')
def view(request, context):
    slot = request.kotti_slot
    # ...

If no view can be found for the given request and slot, the slot remains empty. If you want to force your slot not to be rendered, raise pyramid.exceptions.PredicateMismatch inside your view:

from pyramid.exceptions import PredicateMismatch

@view_config(name='last_tweets')
def view(request, context):
    if some_condition:
        raise PredicateMismatch()
    return {...}

Usually you’ll want to call kotti.views.slots.assign_slot() inside an includeme function and not on a module level, to allow users of your package to include your slot assignments through the pyramid.includes configuration setting.

kotti.views.slots.assign_slot(view_name, slot, params=None)[source]

Assign view to slot.

Parameters
  • view_name (str) – Name of the view to assign.

  • slot (str) – Name of the slot to assign to. Possible values are: left, right, abovecontent, belowcontent, inhead, beforebodyend, edit_inhead

  • params (dict) – Optionally allows to pass POST parameters to the view.

class kotti.views.slots.RenderLeftSlot(obj, request=None)[source]
class kotti.views.slots.RenderRightSlot(obj, request=None)[source]
class kotti.views.slots.RenderAboveContent(obj, request=None)[source]
class kotti.views.slots.RenderBelowContent(obj, request=None)[source]
class kotti.views.slots.RenderInHead(obj, request=None)[source]
class kotti.views.slots.RenderBeforeBodyEnd(obj, request=None)[source]
class kotti.views.slots.RenderEditInHead(obj, request=None)[source]