[Zope] Embedding absolute_url in TAL Syntax

Dan Shafer pydan@danshafer.com
Fri, 07 Jun 2002 00:03:50 -0700


--Boundary_(ID_64DcGN78hiV7ZAoiBW+t7w)
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

At 08:54 AM 6/7/2002 +0200, Robert Rottermann wrote:
>Somehow I do  not believe you.
>In your case it aoumts to about the same code.
>Mabe I do not understand your problem really.
>Why donty you send me a dtml-code snippet where your problem is saved the
>dtml-way.

OK. Here's the pure-DTML approach:

<table>
<tr>
<th>Title</th><th>Summary</th>
</tr>
<dtml-in objectValues>
<tr>
<td><dtml-var title></td>
<td><dtml-var Summary></td>
</tr>
</dtml-in>
</table>

Now here's the DTML approach where I'm using a Python script to retrieve 
the records and then feeding them to the page:

<table>
<tr>
<th>Title</th><th>Summary</th>
</tr>
<dtml-in expr="ListAllArticles()">
<tr>
<td><a href="<dtml-var absolute_url>"><dtml-var title></a> </td>
<td><dtml-var Summary></td>
</tr>
</dtml-in>
</table>

Note that I added the URL stuff here, but including it in the earlier 
example would also be trivial.

What I ended up with in TAL is pretty clean as well. It is simply that 
while absolute_url is a dtml-var that gets picked up without any extra 
effort on my part, when I go to TAL and want to use a Python script, as I 
understand it, I have to stuff the results into a Python list or dictionary 
to make them work with TAL. So I "lose contact" with the object, as it 
were, which means I have to grab any information I want about the object 
*before* I pass to the TAL processing.

My comment about it being more obtuse was based not on what I eventually 
got working but on the code snippets you were sending, which I had a hard 
time following, probably because of my relative inexperience.

>Robert
>----- Original Message -----
>From: "Dan Shafer" <pydan@danshafer.com>
>To: "Robert Rottermann" <robert@redcor.ch>
>Cc: <zope@zope.org>
>Sent: Friday, June 07, 2002 8:44 AM
>Subject: Re: [Zope] Embedding absolute_url in TAL Syntax
>
>
> > Thanks, Robert. I'll study these snippets and see if I can make the
> > technique work.
> >
> > Boy, it sure seems that this ZPT/TAL stuff, far from simplifying the
> > perceived complexity of DTML, is making things *much* more difficult and
> > obtuse. The same code using DTML is quite straight-forward.
> >
> > At 07:35 AM 6/7/2002 +0200, Robert Rottermann wrote:
> > >That probably means, that your item does not have an absolute_url method.
> > > >From the name of ListAllArticlesDict I assume it is a dictonary.  Then
>of
> > >course the items do not have an absolute_url.
> > >Hovever you could get at the "real" object and then use its absolute_url
> > >like so:
> > >
> > ><a  tal:define="obj python:getattr(here, item['id'])"
> > >     tal:attributes="href obj/absolute_url"
> > >     tal:content="item/title">
> > ></a>
> > >I assume your dictionary has an entry 'id' with the objects id.
> > >
> > >Here is a codesnippet I copied verbatim from one of my scripts that uses
> > >absolute_url:
> > ><span tal:define="vlist request/vlist | options/vlist | python:[''] *
> > >here.getNoOfArtikels()"
> > >     tal:omit-tag=""
> > >     tal:repeat="artikel python:here.objectValues('Photo')">
> > >     <tr>
> > >         <td width="100" rowspan="2" valign="top">
> > >                 <img alt="bild" style="margin-right:10"
> > >                 tal:condition="python:artikel.size() &gt; 0"
> > >                 tal:attributes="src python:'%s?display=thumbnail' %
> > >artikel.absolute_url()">
> > >         </td>
> > >Robert
> > >----- Original Message -----
> > >From: "Dan Shafer" <pydan@danshafer.com>
> > >To: "Robert Rottermann" <robert@redcor.ch>
> > >Cc: "Dan Shafer" <pydan@danshafer.com>; <zope@zope.org>
> > >Sent: Friday, June 07, 2002 2:34 AM
> > >Subject: Re: [Zope] Embedding absolute_url in TAL Syntax
> > >
> > >
> > > > Thanks, Robert. But that produces a runtime Zope error:
> > > >
> > > > Error Type: Undefined
> > > > Error Value: "absolute_url" not found in "item/absolute_url"
> > > >
> > > > For completeness, here's the entire relevant snippet:
> > > >
> > > >          <tbody tal:repeat="item here/ListAllArticlesDict">
> > > >          <tr>
> > > >              <td>
> > > >               <a tal:attributes="href item/absolute_url"
> > > >                  tal:content="item/title"></a></td>
> > > >              <td tal:content="item/Summary">Summary</td>
> > > >          </tr>
> > > >          </tbody>
> > > >
> > > > We know that the first line produces the items because if I don't try
>to
> > >do
> > > > the URL, the table displays as expected.
> > > >
> > > > At 11:45 PM 6/6/2002 +0200, Robert Rottermann wrote:
> > > > >In this case you must use tal:attributes
> > > > ><a tal:attributes="href item/absolute_url"
>tal:content="item/title"></a>
> > > > >Robert
> > > > >----- Original Message -----
> > > > >From: "Dan Shafer" <pydan@danshafer.com>
> > > > >To: <zope@zope.org>
> > > > >Sent: Thursday, June 06, 2002 9:48 PM
> > > > >Subject: [Zope] Embedding absolute_url in TAL Syntax
> > > > >
> > > > >
> > > > > > OK, now that I have my table of objects produced by a Python
>script
> > > > >working
> > > > > > in ZPT, I need to figure out how to connect an entry in the table
>to
> > >its
> > > > > > URL. What is the TAL equivalent of:
> > > > > >
> > > > > > <td><a href="<dtml-var absolute_url>"><dtml-var title></a></td>
> > > > > >
> > > > > > It *seemed* like I should be able to code:
> > > > > >
> > > > > > <td><a
> > > > > >
> >
> >href="tal:content='item/absolute_url'"><tal:content="item/title"></a></td>
> > > > > >
> > > > > > But that creates a compilation error in the TAL HTML Parser. Maybe
> > >it's a
> > > > > > quoting thing (which I had sort of hoped would be cleaner in ZPT
>than
> > >it
> > > > >is
> > > > > > with DTML stuff) but I can't find anything in the docs about using
> > > > > > absolute_url in TAL, so I'm kinda stuck.
> > > > > >
> > > > > >
> > > > > >
> > > > > > _______________________________________________
> > > > > > Zope maillist  -  Zope@zope.org
> > > > > > http://lists.zope.org/mailman/listinfo/zope
> > > > > > **   No cross posts or HTML encoding!  **
> > > > > > (Related lists -
> > > > > >  http://lists.zope.org/mailman/listinfo/zope-announce
> > > > > >  http://lists.zope.org/mailman/listinfo/zope-dev )
> > > > > >
> > > >
> > > >
> >
> > Dan Shafer, Chief Scribe and Tablet Keeper
> > PythonCard Open Source Project
> > http://pythoncard.sourceforge.net
> >
> >

Dan Shafer, Chief Scribe and Tablet Keeper
PythonCard Open Source Project
http://pythoncard.sourceforge.net

--Boundary_(ID_64DcGN78hiV7ZAoiBW+t7w)
Content-type: text/html; charset=us-ascii
Content-transfer-encoding: 7BIT

<html>
At 08:54 AM 6/7/2002 +0200, Robert Rottermann wrote:<br>
<blockquote type=cite class=cite cite>Somehow I do&nbsp; not believe
you.<br>
In your case it aoumts to about the same code.<br>
Mabe I do not understand your problem really.<br>
Why donty you send me a dtml-code snippet where your problem is saved
the<br>
dtml-way.</blockquote><br>
OK. Here's the pure-DTML approach:<br><br>
<font face="Times New Roman, Times">&lt;table&gt;<br>
&lt;tr&gt;<br>
&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Summary&lt;/th&gt;<br>
&lt;/tr&gt;<br>
&lt;dtml-in objectValues&gt;<br>
&lt;tr&gt;<br>
&lt;td&gt;&lt;dtml-var title&gt;&lt;/td&gt;<br>
&lt;td&gt;&lt;dtml-var Summary&gt;&lt;/td&gt;<br>
&lt;/tr&gt;<br>
&lt;/dtml-in&gt;<br>
&lt;/table&gt;<br><br>
</font>Now here's the DTML approach where I'm using a Python script to
retrieve the records and then feeding them to the page:<br><br>
<font face="Times New Roman, Times">&lt;table&gt;<br>
&lt;tr&gt;<br>
&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Summary&lt;/th&gt;<br>
&lt;/tr&gt;<br>
&lt;dtml-in expr=&quot;ListAllArticles()&quot;&gt;<br>
&lt;tr&gt;<br>
&lt;td&gt;&lt;a href=&quot;&lt;dtml-var
absolute_url&gt;&quot;&gt;&lt;dtml-var title&gt;&lt;/a&gt;
&lt;/td&gt;<br>
&lt;td&gt;&lt;dtml-var Summary&gt;&lt;/td&gt;<br>
&lt;/tr&gt;<br>
&lt;/dtml-in&gt;<br>
&lt;/table&gt;<br><br>
</font>Note that I added the URL stuff here, but including it in the
earlier example would also be trivial.<br><br>
What I ended up with in TAL is pretty clean as well. It is simply that
while absolute_url is a dtml-var that gets picked up without any extra
effort on my part, when I go to TAL and want to use a Python script, as I
understand it, I have to stuff the results into a Python list or
dictionary to make them work with TAL. So I &quot;lose contact&quot; with
the object, as it were, which means I have to grab any information I want
about the object *before* I pass to the TAL processing.<br><br>
My comment about it being more obtuse was based not on what I eventually
got working but on the code snippets you were sending, which I had a hard
time following, probably because of my relative inexperience.<br><br>
<blockquote type=cite class=cite cite>Robert<br>
----- Original Message -----<br>
From: &quot;Dan Shafer&quot; &lt;pydan@danshafer.com&gt;<br>
To: &quot;Robert Rottermann&quot; &lt;robert@redcor.ch&gt;<br>
Cc: &lt;zope@zope.org&gt;<br>
Sent: Friday, June 07, 2002 8:44 AM<br>
Subject: Re: [Zope] Embedding absolute_url in TAL Syntax<br><br>
<br>
&gt; Thanks, Robert. I'll study these snippets and see if I can make
the<br>
&gt; technique work.<br>
&gt;<br>
&gt; Boy, it sure seems that this ZPT/TAL stuff, far from simplifying
the<br>
&gt; perceived complexity of DTML, is making things *much* more difficult
and<br>
&gt; obtuse. The same code using DTML is quite straight-forward.<br>
&gt;<br>
&gt; At 07:35 AM 6/7/2002 +0200, Robert Rottermann wrote:<br>
&gt; &gt;That probably means, that your item does not have an
absolute_url method.<br>
&gt; &gt; &gt;From the name of ListAllArticlesDict I assume it is a
dictonary.&nbsp; Then<br>
of<br>
&gt; &gt;course the items do not have an absolute_url.<br>
&gt; &gt;Hovever you could get at the &quot;real&quot; object and then
use its absolute_url<br>
&gt; &gt;like so:<br>
&gt; &gt;<br>
&gt; &gt;&lt;a&nbsp; tal:define=&quot;obj python:getattr(here,
item['id'])&quot;<br>
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; tal:attributes=&quot;href
obj/absolute_url&quot;<br>
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;
tal:content=&quot;item/title&quot;&gt;<br>
&gt; &gt;&lt;/a&gt;<br>
&gt; &gt;I assume your dictionary has an entry 'id' with the objects
id.<br>
&gt; &gt;<br>
&gt; &gt;Here is a codesnippet I copied verbatim from one of my scripts
that uses<br>
&gt; &gt;absolute_url:<br>
&gt; &gt;&lt;span tal:define=&quot;vlist request/vlist | options/vlist |
python:[''] *<br>
&gt; &gt;here.getNoOfArtikels()&quot;<br>
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; tal:omit-tag=&quot;&quot;<br>
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; tal:repeat=&quot;artikel
python:here.objectValues('Photo')&quot;&gt;<br>
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br>
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td
width=&quot;100&quot; rowspan=&quot;2&quot;
valign=&quot;top&quot;&gt;<br>
&gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;img alt=&quot;bild&quot; style=&quot;margin-right:10&quot;<br>
&gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
tal:condition=&quot;python:artikel.size() &amp;gt; 0&quot;<br>
&gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
tal:attributes=&quot;src python:'%s?display=thumbnail' %<br>
&gt; &gt;artikel.absolute_url()&quot;&gt;<br>
&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/td&gt;<br>
&gt; &gt;Robert<br>
&gt; &gt;----- Original Message -----<br>
&gt; &gt;From: &quot;Dan Shafer&quot; &lt;pydan@danshafer.com&gt;<br>
&gt; &gt;To: &quot;Robert Rottermann&quot; &lt;robert@redcor.ch&gt;<br>
&gt; &gt;Cc: &quot;Dan Shafer&quot; &lt;pydan@danshafer.com&gt;;
&lt;zope@zope.org&gt;<br>
&gt; &gt;Sent: Friday, June 07, 2002 2:34 AM<br>
&gt; &gt;Subject: Re: [Zope] Embedding absolute_url in TAL Syntax<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; &gt; Thanks, Robert. But that produces a runtime Zope
error:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Error Type: Undefined<br>
&gt; &gt; &gt; Error Value: &quot;absolute_url&quot; not found in
&quot;item/absolute_url&quot;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; For completeness, here's the entire relevant 
snippet:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;tbody tal:repeat=&quot;item here/ListAllArticlesDict&quot;&gt;<br>
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;tr&gt;<br>
&gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;td&gt;<br>
&gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;a tal:attributes=&quot;href item/absolute_url&quot;<br>
&gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
tal:content=&quot;item/title&quot;&gt;&lt;/a&gt;&lt;/td&gt;<br>
&gt; &gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;td tal:content=&quot;item/Summary&quot;&gt;Summary&lt;/td&gt;<br>
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/tr&gt;<br>
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/tbody&gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; We know that the first line produces the items because if
I don't try<br>
to<br>
&gt; &gt;do<br>
&gt; &gt; &gt; the URL, the table displays as expected.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; At 11:45 PM 6/6/2002 +0200, Robert Rottermann wrote:<br>
&gt; &gt; &gt; &gt;In this case you must use tal:attributes<br>
&gt; &gt; &gt; &gt;&lt;a tal:attributes=&quot;href
item/absolute_url&quot;<br>
tal:content=&quot;item/title&quot;&gt;&lt;/a&gt;<br>
&gt; &gt; &gt; &gt;Robert<br>
&gt; &gt; &gt; &gt;----- Original Message -----<br>
&gt; &gt; &gt; &gt;From: &quot;Dan Shafer&quot;
&lt;pydan@danshafer.com&gt;<br>
&gt; &gt; &gt; &gt;To: &lt;zope@zope.org&gt;<br>
&gt; &gt; &gt; &gt;Sent: Thursday, June 06, 2002 9:48 PM<br>
&gt; &gt; &gt; &gt;Subject: [Zope] Embedding absolute_url in TAL
Syntax<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; OK, now that I have my table of objects produced
by a Python<br>
script<br>
&gt; &gt; &gt; &gt;working<br>
&gt; &gt; &gt; &gt; &gt; in ZPT, I need to figure out how to connect an
entry in the table<br>
to<br>
&gt; &gt;its<br>
&gt; &gt; &gt; &gt; &gt; URL. What is the TAL equivalent of:<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; &lt;td&gt;&lt;a href=&quot;&lt;dtml-var
absolute_url&gt;&quot;&gt;&lt;dtml-var
title&gt;&lt;/a&gt;&lt;/td&gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; It *seemed* like I should be able to code:<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; &lt;td&gt;&lt;a<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt;<br>
&gt;href=&quot;tal:content='item/absolute_url'&quot;&gt;&lt;tal:content=&quot;item/title&quot;&gt;&lt;/a&gt;&lt;/td&gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; But that creates a compilation error in the TAL
HTML Parser. Maybe<br>
&gt; &gt;it's a<br>
&gt; &gt; &gt; &gt; &gt; quoting thing (which I had sort of hoped would
be cleaner in ZPT<br>
than<br>
&gt; &gt;it<br>
&gt; &gt; &gt; &gt;is<br>
&gt; &gt; &gt; &gt; &gt; with DTML stuff) but I can't find anything in
the docs about using<br>
&gt; &gt; &gt; &gt; &gt; absolute_url in TAL, so I'm kinda stuck.<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;
_______________________________________________<br>
&gt; &gt; &gt; &gt; &gt; Zope maillist&nbsp; -&nbsp; Zope@zope.org<br>
&gt; &gt; &gt; &gt; &gt;
<a href="http://lists.zope.org/mailman/listinfo/zope" eudora="autourl">http://lists.zope.org/mailman/listinfo/zope</a><br>
&gt; &gt; &gt; &gt; &gt; **&nbsp;&nbsp; No cross posts or HTML
encoding!&nbsp; **<br>
&gt; &gt; &gt; &gt; &gt; (Related lists -<br>
&gt; &gt; &gt; &gt; &gt;&nbsp;
<a href="http://lists.zope.org/mailman/listinfo/zope-announce" eudora="autourl">http://lists.zope.org/mailman/listinfo/zope-announce</a><br>
&gt; &gt; &gt; &gt; &gt;&nbsp;
<a href="http://lists.zope.org/mailman/listinfo/zope-dev" eudora="autourl">http://lists.zope.org/mailman/listinfo/zope-dev</a>
)<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt;<br>
&gt; Dan Shafer, Chief Scribe and Tablet Keeper<br>
&gt; PythonCard Open Source Project<br>
&gt; <a href="http://pythoncard.sourceforge.net/" eudora="autourl">http://pythoncard.sourceforge.net</a><br>
&gt;<br>
&gt;</blockquote>
<x-sigsep><p></x-sigsep>
Dan Shafer, Chief Scribe and Tablet Keeper<br>
PythonCard Open Source Project<br>
<a href="http://pythoncard.sourceforge.net/" eudora="autourl">http://pythoncard.sourceforge.net<br>
</a></html>

--Boundary_(ID_64DcGN78hiV7ZAoiBW+t7w)--