2012-05-22 94 views
1

我是Mako的全新新人,所以請耐心等待。魔方中的障礙物和Defs

我有一系列的塊用於佈局。其中一個塊需要在同一頁面上聲明一些變量。我無法讓它正常工作。這是非常基本的,我知道,但我正在學習,無法在Mako文檔中找到解決方案。什麼是適當的語法和/或方法來做到這一點?

我想保持userInputViews更全球化,因爲它在其他區塊中也同樣使用。 currentSet的值是任意的,因爲它被傳遞給頁面並且工作正常,所以不會被分析。

我得到的錯誤是關於userInputViews未定義的。

 
<% 
userInputViews = [ 
    "MediatorAddress", 
    "MediatorDateOfBirth", 
    "MediatorEmailAddress" 
] 
%> 

<%block name="contentAction"> 
    % if set(userInputViews) == set(currentSet): 
    user inputs are currently selected 
    % endif 
</%block> 
+0

我不知道,但你可以嘗試設置($ userInputViews) – avasal

+0

只是試了一下,並得到了語法錯誤。雖然 – AlexM

+0

可能是這可以是一些幫助.. http://stackoverflow.com/questions/4161464/pass-in-variable-to-mako-template – avasal

回答

2

我只是想學真子自己,但我相信,你已經宣佈在不同的命名空間比塊userInputViews。

http://docs.makotemplates.org/en/latest/runtime.html

建議調用一個空字典渲染爲「變量」,然後將您的「全局」變量到字典。

尋找 那麼,如果我想在模板請求中爲每個人設置全局值? 對於這個例子