How to access an array with TAL

357 views Asked by At

I have a python file which creates an array with a path to an image and a page URL

self.banner1 = [self.context.defaultBanner1.filename,self.context.defaultBanner1bUrl]

I want to access this within my page using TAL. I have tried this without success

<h1 tal:content="view/banner1[0]"></h1>

How do I access the array using TAL?

2

There are 2 answers

0
David Glick On BEST ANSWER

You can't do that with a path expression, but you can use a Python expression:

<h1 tal:content="python:view.banner1[0]" />
0
Jihaisse On

You could have a view that make it for you (and test if the array is not empty).

def get_banner(self, banner):
    """ """
    if banner:
        return banner[0]

In the template :

<h1 tal:content="view/get_banner"></h1>