[silva-dev] Template-trouble
Clemens Robbenhaar
robbenhaar at espresto.com
Tue Jul 13 20:52:01 CEST 2004
Hi Yuri,
> Hi Clemens,
>
> >>Hm, I have never heard about this CoolMenus stuff ... however
> >>if You want to filter for non-empty folders,
> >> You maybe could use the "is_published" method [ ... ]
> The method works fine, thanks.
> However, combining "is_published" with Coolmenu's Javascript puzzles me.
>
> I managed to get it working, but it looks very sloppy:
>
> [snip[
>
> <script tal:condition="here/portfolio/is_published">
> oM.makeMenu('portfolio','','','/twin/portfolio/','',83,16,'/twin/images/nav/hoofdmenu/03_portfolio.gif','/twin/images/nav/hoofdmenu/03_portfolio_mo.gif','','','top')
> </script>
> <script tal:condition="here/opdrachtgevers/is_published">
> oM.makeMenu('opdrachtgevers','','','/twin/opdrachtgevers/','',122,16,'/twin/images/nav/hoofdmenu/04_opdrachtgevers.gif','/twin/images/nav/hoofdmenu/04_opdrachtgevers_mo.gif','','','top')
> </script>
> <script tal:condition="here/contact/is_published">
> oM.makeMenu('contact','','','/twin/contact/','',75,16,'/twin/images/nav/hoofdmenu/05_contact.gif','/twin/images/nav/hoofdmenu/05_contact_mo.gif','','','top')
> </script>
>
> [/snip]
>
I guess its more a problem with page templates treating scripts badly.
For some reasons page templates do ignore tal:-expressions inside
<script>-tags intentionally. This is a design decision made too long ago
to discuss its pros and cons thus I do not do it here.
The work around I use in this case is including a python script, which
does the rendering code. In Your case this may look like:
<script_dummy tal:replace="strcuture here/get_js_stuff" />
in the layout macro.
Beside this in the Silva Root put a python script "get_js_stuff"
which does something like:
rendered = []
for content in context.get_ordered_publishables():
if not content.is_published():
continue
rendered.append('<script type="text/javascript">')
rendered,append("""
oM.makeMenu('%s','','','%s/','',83,16,'/twin/images/nav/hoofdmenu/%s','/twin/images/nav/hoofdmenu/%s','','','top')
""" % (content.getId(), contenbt.absolute_url(),
container.get_image_id(content),
container.get_image_id2(content)
)
rendered.append('</script>')
return '\n'.join(rendered)
I admit I did not understand where the eight and ninth argument to the
oM.makeMenu came from, thus I replaced them with calls to two more, yet
to be written scripts, "get_image_id" and "get_image_id2". For example
"get_image_id(portfolio)" should return "03_portfolio.gif", while
"get_image_id(opdrachtgevers)" should return "04_opdrachtgevers.gif".
Chances are high this is not the way to do it, but I hope You can
figure out the right way to do it.
The usual disclaimer: Everything untested and modulo a lot of typos.
Cheers,
Clemens
More information about the silva-dev
mailing list