Hi All,

Can someone please tell me if there is a way to render macros for a 
browser view template, i.e an instance of SimpleViewClass?

I tried to use macroContent in plone/app/kss/plonekssview.py but ran 
into some problems.

I'm using plone.app.kss-1.4.3-py2.4.egg

The error I get is:

>   Module plone.app.kss.plonekssview, line 35, in macroContent
> RuntimeError: Macro not found

Upon closer inspection through a pdb trace:

> (Pdb) l
>  24           jointpath = '/'.join(path[:-2]).encode('ascii')
>  25           macroobj = self.context.restrictedTraverse(jointpath)
>  26           import pdb; pdb.set_trace()
>  27  ->               the_macro = macroobj.macros[path[-1]]
>  (Pdb) p macroobj
> <Products.Five.metaclass.SimpleViewClass from 
> /home/jc/work/ClassicFM/buildout/trunk/parts/development-products/ClassicFMSite/browser/templates/podcast-detail.pt
>  object at 0xe49a98c>

> (Pdb) p macroobj.macros
> *** AttributeError: <exceptions.AttributeError instance at 0xd8d53cc>]

So the SimpleViewClass instance does not have a macros attributes, but 
after some investigation I saw that I could access the macros through 
the index attribute as follows:

> (Pdb) macroobj.index.macros.keys()
> ['podcast_item']

So, in trying to understand what macroobj.index is, I do the following:

> (Pdb) p macroobj.index
> <ImplicitAcquirerWrapper object at 0xdea502c>
> (Pdb) p macroobj.index.aq_inner
> <ImplicitAcquirerWrapper object at 0xdea62cc>

Which didn't really explain it to me.

Since realising this, I've modified macroContent as follows:

> try:
>     the_macro = macroobj.macros[path[-1]]
> except  AttributeError:
>     # XXX: My customization, the only way I could get macros 
>     # of browser templates to render. - JC Brand
>     the_macro = macroobj.index.macros[path[-1]]
> except IndexError:
>     raise RuntimeError, 'Macro not found'

and macroContent now renders macros in my browser view templates.

But at the moment, I still don't really understand what the index 
attribute points to... it looks to me like a template object of the type 
you get with skins templates, but I'm not sure.

Also, I don't know if there is a better and more elegant way of doing 
this, without having to hack macroContent.

Any comments and help welcome.

Thanks a lot

JC



_______________________________________________
Kss-devel mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kss-devel

Reply via email to