On Friday, September 16, 2005 4:05 PM, Benji York wrote:

> Garrett Smith wrote:
>> If it's just a patch to get 'rich' widgets working, I'll stick with
>> my initial impression of it being too magical.
> 
> The main reasons why this isn't a problem individual widgets
> can solve
> is that 1) they can't know if things that should only be done once
> have already been done (include JavaScript for example), 2) they can't
> directly add entries to the <head> section of the page, and 3) the
> components that require the JS or CSS might not be widgets at all.

That's right. But the view can solve these problems easily without a lot of 
other stuff like yet-another-ZCML directive and automagical transformation of 
the HTML head element.

This is what we have:

class IHeadContent(Interface):
    """Something that provides head content for a page."""

    def headContent():
        """Returns a sequence of HTML snippets to be added to the page head."""

class SomeView(BrowserView):

    def __init__(self, context, request):
        ...
        self.headContent = []
        for widget in self.widgets():
            hc = zapi.queryAdapter(widget, IHeadContent)
            if hc is not None:
                for content in hc.headContent:
                    if content not in self.headContent:
                        self.headContent.append(content)
        ...

The applicable PT:

    <head>
        <tal:block repeat="content view/headContent">
            <tal:block content="structure content" />
        </tal:block>
        ...
    </head>

This is a trivial change to the existing Zope code.

 -- Garrett
_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to