[Zope-CMF] Re: ZPT in CMF

Leon de Heus leon@pruts.nl
03 Dec 2001 16:54:36 +0100


Op Mon 03-12-2001, om 16:30 schreef seb bacon:
> * Leon de Heus <leon@hapkido.nl> [011203 13:52]:
> > Reusable components: as reusable components (a.k.a. 'Library Items' in
> > Dreamweaver) the metal:use-macro elements are created and made available
> > for use in other pages. Depending on the editor used, they can be made
> > available as files (for use in Dreamweaver) or as draggable and
> > droppable html fragments for use in the Internet Explored editing
> > component. What the Dreamweaver or IE users are dragging and dropping
> > are the correct pieces of zpt code to use the macro, with the example
> > rendered inside (a la 'expand macros' setting in the ZPT edit screen). 
> 
> Could you go into a little more detail about how this works?  ('made
> available as files')...

I'll use the example of Dreamweaver for this. I don't know how much you
know about it. I'm not a Dreamweaver user, but together with our
webdesigner (he was the cause of all this ;-) ) we came to this
solution:

Dreamweaver can use 'Library Items'. They are what you expect them to
be: reusable html fragments which can be used in pages. Dreamweaver adds
comments around them, and it won't let you change the fragments when you
use them. If you wanna edit them you have to edit the library items
themselves. If you edit the library items, then DW updates all the pages
using them. 

Generating libary items
-----------------------

Building a 'library item' from a zope object is done by using the needed
zpt syntax:

<div metal:use-macro="path_to_macro">

   <p>... stuff ...</p>

</div>

The script which generates fragments like this would be like:
- use xmlparser to parse the page which contains the macro's
- change all 'define-macro' attributes to 'use-macro' + the correct path
- generate a file for each macro

The files are placed inside zope and ftp'd to the Dreamweaver workspace
for using them. A somewhat cleaner solution would probably be to
generate a zip archive.


Wrappers for saving and editing
--------------------------------

When the pages are saved we used a wrapper script which would first
remove all the Dreamweaver comments. For Library Items DW adds comments
like "<!--# Begin Library Item /path_to_libary_item -->".

To generate the editable version of a page for Dreamweaver the opposite
is done.


Fun ;)
-----
Fun is that the same thing was easily implemented for WYSIWYG editing in
Internet Explorer. This time "contentEditable=false" needs to be added
to the elements with the 'metal:use-macro' attributes. A live example is
allways present (great for WYSIWYG ;) ) when the pagetemplate source is
requested with 'expand macros' on. But the content it self is not
editable by the editor.

Hm, not very easy to explain it all in a short email. But if you have
more questions about it I'll be happy to answer them :)

Best,
Leon.