2015-04-23 33 views
0

設置的Freemarker變量是否可以設置一個或多個變量的freemarker在類似情況下:FMPP:如何從一個BeanShell的腳本

<#assign test=pp.loadData('eval', ' 
a="test1"; 
b="test2"; 
return "test";')> 
在freemarker的腳本

,並有機會獲得A和B?

+0

你可以將它設置在config.fmpp文件。你能這樣做嗎? – ratherblue

+0

我想要做的是在bsh中解析一個字符串並將其分解爲幾個freemarker變量。 – PPH

回答

0

我想不寫一個自定義DataLoader不能完成。我在說「猜」,因爲也許我不知道一個BeanShell的竅門。我能得到的最接近的是使用return this.namespace;,然後使用${test.getVariable('a')}。當然這太冗長了。

更新: 其實,下面恐怖是更近:

<#assign test=pp.loadData('eval', ' 
    a="test1"; 
    b="test2"; 

    // This should be factored out into a common function somehow 
    ns = this.namespace; 
    vars = new HashMap(); 
    for (name : ns.getVariableNames()) { 
     vars.put(name, ns.getVariable(name)); 
    } 
    return vars; 
')> 

${test.a} 
+0

好的,謝謝,它適合我。它不適用於生產環境。 – PPH