2012-08-13 47 views
1

考慮以下解析的模板和循環其root.nodelist:列出液體模板中的所有節點?

text = '{% if true %}{{ "poland" | capitalize }}{% else %}{{ "portugal" | capitalize}}{% endif %}' 
template = Liquid::Template.parse(text) 
template.root.nodelist.each { |node| p node } 

只打印:

Portugal 

(而不是波蘭)

怎麼會一個列表中的所有節點(包括液體變量,標籤等)從模板?特別是那些內部的if/else邏輯?

回答

0

我是不是真的能找到一個直接的方式來訪問的條件塊,但我用一種變通方法的方法添加到類用下面的代碼

def b 
    @blocks 
end 

,然後使用這個代碼

template.root.nodelist[0].b.each { |a| p a.attachment[0].name } 

我能找到你正在尋找

名單