[Zope] Creating links dynamically

John Poltorak jp at warpix.org
Tue May 31 15:47:20 EDT 2005


On Tue, May 31, 2005 at 07:17:46PM +0300, Vital Lobachevsky wrote:
> John Poltorak wrote:
> > On Tue, May 31, 2005 at 06:23:11PM +0300, Vital Lobachevsky wrote:
> > 
> > Many thanks for your suggestion.
> > 
> > Is there a worked example of doing this anywhere?
> > 
> > There seem to be quite a few steps involved in trying to get this working 
> > and I'm no expert in writing python scripts, and it will probably take me 
> > a couple of days to get this working.
> 
> Well, it's really easy. Create 'linkList' (Python Script) in the folder 
> where you page lives or somewhere higher in folder hierarchy:
> 
> ## Script (Python) "linkList"
> return [
>    ('http://www.google.com/', 'Google'),
>    ('http://www.yahoo.com/', 'Yahoo'),
> ]
> 
> If your page is Page Template, it maybe something like this
> 
> <html>
> <body>
> <h1>Search Engines</h1>
> <tal:block repeat="item here/linkList">
>    <a tal:content="python:item[1]"
>       tal:attributes="href python:item[0]"></a><br />
> </tal:block>
> </body>
> </html>
> 
> If you page is DTML Method, you can do the same using <dtml-in> tag.

Thanks for the suggestion, but I really am a novice when it comes to all 
this and you are probably presuming more expertise than I have.

I created a Page Template exactly as you suggested. It's called test and 
is in the testsite folder - the contents are pasted from your example. 

The python script was pasted into a file object called linkList  which has 
a Content Type of text/x-unknown-content-type.

When I load the 'test' file and click on the Test tab I get:-


Zope Error

Zope has encountered an error while publishing this resource.

Error Type: AttributeError
Error Value: __getitem__ 
 

Any ideas on what I have missed out or where to look for a working 
example?


-- 
John




More information about the Zope mailing list