[Zope-CMF] Using CMF metadata in ZPT pages - why are these two different?

Anton Hughes Anton.Hughes at utas.edu.au
Wed Sep 17 19:15:35 EDT 2003


Hi All,

I'm using the following ZPT in my CMFDefault site (borrowed from the ZopeZen
Plone skin) in a local_pt page to display the Subject metadata element (or
corresponding image) for news items in my site:

    <div tal:repeat="news batchnews">
          <span class="newsItemSubject" tal:condition="news/Subject">
            <span tal:omit-tag="" tal:define="img
python:here.getSubjectImage(news['Subject'])">
                <a tal:attributes="href
python:here.portal_url()+'/search?portal_type=News%20Item&Subject='+news.Sub
ject[0];"><span tal:condition="img" tal:replace="structure img" />
                <b tal:condition="not:img">[&nbsp;<span
tal:replace="python:news['Subject'][0]" />&nbsp;]</b></a><br />
            </span>
          </span>
    </div>

Which works absolutely fine. However, when I try and use the same code in
newsitem_view as follows:

          <span class="newsItemSubject" tal:condition="here/Subject">
            <span tal:omit-tag="" tal:define="img
python:here.getSubjectImage(here['Subject'])">
                <a tal:attributes="href
python:here.portal_url()+'/search?portal_type=News%20Item&Subject='+here.Sub
ject[0];"><span tal:condition="img" tal:replace="structure img" />
                <b tal:condition="not:img">[&nbsp;<span
tal:replace="python:here['Subject'][0]" />&nbsp;]</b></a><br />
            </span>
          </span>

it doesn't work. First I got __getitem__ errors, so I replaced
here['Subject'] with here/subject. Then the tal:condition statement in the
first line failed (is false) so nothing appears. When I took out the
tal:condition statement, I got an error saying 'global Subject is not
defined'. Here is the working code:

  <span class="newsItemSubject" tal:define="sub here/Subject"
tal:condition="python:sub[0]">
        <span tal:omit-tag="" tal:repeat="subj sub">
        <span tal:omit-tag="" tal:define="img
python:here.getSubjectImage((subj,))">
             <a tal:attributes="href
python:here.portal_url()+'/search?portal_type=News%20Item&Subject='+subj;"><
span tal:condition="img" tal:replace="structure img" />
             <b tal:condition="not:img">[&nbsp;<span
tal:replace="python:subj" />&nbsp;]</b></a><br />
        </span>
        </span>
  </span>

What I would like to understand is why ostensibly identical TAL expressions
operate so differently between the two contexts - I suspect there is
something different about the here variable...

Thanks,

Anton Hughes

Data Administrator
Childhood Determinants of Adult Health Project
Menzies Centre for Population Health Research
Private Bag 23, Hobart Tasmania 7001

Email: anton.hughes at utas.edu.au
Web:  http://www.menzies.utas.edu.au/cohort/CDAH.htm
Phone: +61 (0) 3 6226 7761

=+=+++=====+++++++++=================+++++++++++++++++++++++++++++++
If you wrap the Internet around every person on the planet and spin the
planet, 
software flows in the network.
           -- Moglen's Metaphorical Corollary to Faraday's Law



More information about the Zope-CMF mailing list