[Zope] passing args from zpt to zpt

Dragos Chirila d.chirila at finsiel.ro
Thu May 13 08:43:42 EDT 2004


Hi

Let's say you have 2 ZPT's in the same folder, named x and y.

x will call y with a parameter:

x
---
<html>
  <head>
    <title tal:content="template/title">The title</title>
  </head>
  <body>
      Value from y:<br>
      <tal:block define="body
python:here.y.pt_render(extra_context={'here':here, 'value': 10})">
      <span tal:replace="structure body"/>
      </tal:block>
  </body>
</html>

y
---
<b><span tal:replace="value"/></b>

Regards,
Dragos

PS:
If you are using this in a python product here is a way to handle this
problem http://zpt.sourceforge.net/.
The class is very simple actually, something like:

manage_addCustomTemplateForm =
PageTemplateFile('PATH_TO_ZPT_CONSTRUCTOR_PAGE', globals())
def manage_addCustomTemplate(self, id='', title='', file='', REQUEST=None):
    """ add a new CusotmTemplate object """
    content_type = None
    if file != '':
        if file.filename:
            headers = getattr(file, 'headers', None)
            content_type = headers.get('content_type')
    ob = Template(id, title, file, content_type)
    self._setObject(id, ob)
    if REQUEST:
        return self.manage_main(self, REQUEST, update_menu=1)

class CustomTemplate(ZopePageTemplate):
    """ the CustomTemplate class """

    meta_type = 'CustomTemplate'
    icon = 'misc_/YOURPRODUCT/template'

    manage_options = (ZopePageTemplate.manage_options)

    security = ClassSecurityInfo()

    def __init__(self, id, title, text, content_type):
        """ initialize the Template """
        ZopePageTemplate.__dict__['__init__'](self, id, text, content_type)
        self.title = title

    def __call__(self, context={}, *args):
        """ """
        if not context.has_key('args'):
            context['args'] = args
        return self.pt_render(extra_context=context)

    def om_icons(self):
        """ """
        icons = ({'path': 'misc_/YOURPRODUCT/picture_for_this_class, 'alt':
self.meta_type, 'title': self.meta_type},)
        if self._v_errors:
            icons = icons + ({'path': 'misc_/PageTemplates/exclamation.gif',
'alt': 'Error', 'title': 'This template has an error'},)
        return icons

InitializeClass(CustomTemplate)

Hope this will help.




> Folks,
>
> Does anyone know if there is a way to pass arguments from a Page Template
to
> another?
> The only way I can think of is to use SESSION to hold the values, and this
> seems
> clunky as I am then forced to remove those arguments from SESSION after.
>
> I need to do something like:
>
>   <!-- my main.pt is as follows -->
>   <span tal:define="global length python:23">
>     <metal:block tal:replace="structure here/nested.pt"/>
>   </span>
>
>   <!-- and nested.pt looks like this -->
>   <b tal:content="length|string:nothing was passed down"/>
>
> For whatever reason, even the global declaration doesn't seem to pass the
value
> on
> down to nested.pt (my understanding of scoping is obviously flawed :).
>
> Thanks,
> Roy.
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Movies - Buy advance tickets for 'Shrek 2'
> http://movies.yahoo.com/showtimes/movie?mid=1808405861
>
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
>





More information about the Zope mailing list