Derek Broughton wrote:

I would perhaps think that using viewlets to compose an XML document is
not something viewlets were designed for.

It wasn't really my intent, it just turned out that a viewlet was a good way
to include another template at the time.  Then my design changed, and
simplified, and in the end I ended up with a single template that needed a
choice of XSL stylesheets, so it was easy enough to remove the viewlet.

I think the main use case for viewlets is when third-party products need to "plug into" the UI at specified points, perhaps for specific contexts and/or views. For example, plone.app.discussion can plug into the area under the content to show discussion threads everywhere that it makes sense.

They are not a good way to break a single template up into a few re-usable chunks. For that, they are overkill.

My turn for a D'oh.  It was using a viewlet because there was originally a
need for a viewlet, but you're absolutely right that this is both a better
idea, and more suited to my current purpose.

Good. :)

Thanks.

(Still, it doesn't seem right that viewlets can have a different content-
type from the view that invokes them),

Agree. I think this is a quirk of the ZPT engine, though. Bear in mind that the viewlet isn't really aware of how the template works. A viewlet just has a render() method that's meant to return some output. Some viewlets' render() method will invoke a ViewPageTemplateFile which in turn executes the ZPT engine over a template file. However, that's not part of the viewlet mechanism: you could just as easily return a hand-coded string or one built using any other templating engine.

Therefore, the problem is more the sniffing that the ZPT engine is doing to go into XML mode. I'm sure there's a way to invoke the ViewPageTemplateFile from render() that forces this without the sniffing, but I'm not sure how. I doubt many people use ZPTs to build XML documents (although it's a perfectly reasonable thing to want to do).

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers

Reply via email to