[ZPT] Structured text in a ZPT

Phil Aylesworth paylesworth@stclaircollege.ca
Tue, 04 Sep 2001 16:33:10 -0400


That is quite a mouthful! When I tried this:

      <font size="2" face="Arial, Helvetica, sans-serif" color="#666666">
       <div tal:define="sfmt 
modules/Products/PythonScripts/standard/special_formats; sttxt 
nocall:sfmt/structured-text">
         <span tal:replace="structure python:sttxt(blurb)">
           Blurb goes here.
         </span>
       </div>
      </font>


I got an error:

 <http://RobinsonHarleyDavidson.com/banner/redirect?link=http%3a//www.kanetix.com>exceptions.KeyError on modules in ""



Traceback (innermost last):
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 223, in publish_module
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 187, in publish
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook
    (Object: CatalogAware)
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 171, in publish
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/ZPublisher/mapply.py, line 160, in mapply
    (Object: index_html)
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/ZPublisher/Publish.py, line 112, in call_object
    (Object: index_html)
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/OFS/DTMLMethod.py, line 189, in __call__
    (Object: index_html)
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/DocumentTemplate/DT_String.py, line 538, in __call__
    (Object: index_html)
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/Shared/DC/Scripts/Bindings.py, line 338, in __render_with_namespace__
    (Object: index.html)
  File /usr/local/Zope-2.3.1-linux2-x86/lib/python/Shared/DC/Scripts/Bindings.py, line 354, in _bindAndExec
    (Object: index.html)
  File /usr/local/zope/lib/python/Products/PageTemplates/ZopePageTemplate.py, line 246, in _exec
    (Object: index.html)
  File /usr/local/zope/lib/python/Products/PageTemplates/PageTemplate.py, line 153, in pt_render
    (Object: index.html)
  File /usr/local/zope/lib/python/TAL/TALInterpreter.py, line 197, in __call__
  File /usr/local/zope/lib/python/TAL/TALInterpreter.py, line 224, in interpret
  File /usr/local/zope/lib/python/TAL/TALInterpreter.py, line 301, in do_setLocal
  File /usr/local/zope/lib/python/Products/PageTemplates/TALES.py, line 257, in evaluate
  File /usr/local/zope/lib/python/Products/PageTemplates/Expressions.py, line 169, in __call__
TALESError: (see above)

However, this does work:

      <font size="2" face="Arial, Helvetica, sans-serif"
            color="#666666" tal:content="here/blurb">
        Whether
        you are looking to purchase a new or used Harley Davidson, or 
parts and
        accessories for your pride and joy, our friendly staff will 
always be
        there to assist you in all your needs.
      </font>

Although, it does not format as structured text as I would like.

I don't know what I am doing here so I just cut and pasted the code that 
you gave me. "blurb" is a property of the ZClass which contains this ZPT.

Can you see what I am doing wrong?

Thanks,

Phil

Evan Simpson wrote:

>From: "Phil Aylesworth" <paylesworth@stclaircollege.ca>
>
>>This has been holding me back from really jumping into ZPT. I hope I
>>
>am
>
>>just overlooking something obvious.
>>
>
>It's not obvious, but it's possible.  You need to use the 'modules'
>variable to get the dictionary of standard formatting functions, like
>this:
>
><div tal:define="sfmt
>modules/Products/PythonScripts/standard/special_formats; sttxt
>nocall:sfmt/structured-text">
>  <span tal:replace="structure python:sttxt(blurb)">The blurb</span>
></div>
>
>All of the DTML formatting functions are accessible through
>special_formats.  Since structured-text emits tags, you need to use the
>'structure' keyword in the tal:replace statement.  Since it's a
>function, you need to use nocall: when making the nickname 'sttxt', to
>avoid prematurely calling it.
>
>Cheers,
>
>Evan @ Zope
>
>
>_______________________________________________
>ZPT mailing list
>ZPT@zope.org
>http://lists.zope.org/mailman/listinfo/zpt
>