Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 python 文件,它创建一个包含图像路径和页面 URL 的数组
self.banner1 = [self.context.defaultBanner1.filename,self.context.defaultBanner1bUrl]
我想使用 TAL 在我的页面中访问它。我试过这个没有成功
<h1 tal:content="view/banner1[0]"></h1>
如何使用 TAL 访问阵列?
您不能使用路径表达式来做到这一点,但您可以使用 Python 表达式:
<h1 tal:content="python:view.banner1[0]" />
你可以有一个为你制作的视图(并测试数组是否不为空)。
def get_banner(self, banner): """ """ if banner: return banner[0]
在模板中:
<h1 tal:content="view/get_banner"></h1>