AW: [Zope3-dev] Re: AW: open-sourcing some ZC widgets (was Re: AW: Widgetproblems? Is there work in progress?)

Roger ineichen dev at projekt01.ch
Tue Jun 1 17:54:49 EDT 2004


Philipp von Weitershausen
> Roger ineichen wrote:
> > If a widget use javascript, where and how should load them?
> > I still think we need a concept for to load additional
> > stuff to the ZMI like widgets javascript without to
> > hardcode them to the template.
> 
> We've essentially run into this problem with kupu. Kupu tries 
> not to be 
> a widget (we think of it as a client-side in-browser app), 
> but the form 
> fetishists at plone.org want it as a widget. When you're a 
> widget, you 
> indeed have no control over what goes into that page's header. ZPT's 
> macro approach can be interpreted as "you don't need to".
> 
> It's really not a problem with JavaScript as <script /> tags can go 
> anywhere. It's really a problem with CSS styles which we 
> currently have 
> to hack in from JavaScript. XML pipelines would do the trick, for 
> example, but that's distant future in Zope, I think.
> 
> Philipp

Ok, you are right, the css is a better example.

I was not happy with the situation and implement
slots in our skin for to resolve this problem
and don't hack arround. Now we can offer a open
skin and everyone can register what he whants.

Optional you can add "local" slots which overrides
them. We use adapters for to lookup the slotpage 
(views) used in this slots.

Perhaps there is a question why we make such a 
big workarround for to do this.

The answer is, the adapter stores the settings 
of a slot in the principal annotation service.
This way each user can have other views in the slots.

A really simply implementation of pagelets or how 
the called. A extension in the future could be
a lookup in the instance annotation for additional 
slots.


How it works:
- Register a slot
- Register views to this slot
- Call this slots in a master template

Now, we get a nice way for to register 
whatever we whant and get them rendered in the 
master template where we call them.

This is used for to register general extensions
like additional javascripts and also CSS Styles.


in configure.zcml register a slot:

<tiks:slot
    name="javascript"
    permission="zope.View"
    />

and somewhere register a slot page (view)

<tiks:slotpage
    for="*"
    slot="javascript" 
    name="xmltree_macro"
    permission="zope.Public"
    template="xmltree.pt"
    />
    
In the master template we use a view called slots which
use the javascript as a attribute:
( The the view slots is a Class with a method 
def __getitem__(self, slotname):
which returns the macro code of the (view) xmltree.pt)

<metal:block tal:repeat="macro views/slots/javascript">
  <metal:block metal:use-macro="macro" />
</metal:block>


If the slotpage looks like:

<div metal:define-macro="xmltree_macro" tal:omit-tag="">
<script type="text/javascript" src="xmltree.js"
        tal:attributes="src string:${context/++resource++xmltree.js}"
></script>
</div>

You get the following output:

<script type="text/javascript"
src="http://localhost:8080/++resource++xmltree.js"></script>

Regards 
Roger




More information about the Zope3-dev mailing list