data = { :users => [{:id=>1},{:id=>2}] }
payload = {users: "{% for user in users %} {{ user.id }} {% endfor %}" }
@template = Liquid::Template.parse(payload.to_json)
@payload = @template.render(data.deep_stringify_keys)
JSON.parse(@payload) # => {"users"=>" 1 2 "}
可以看到最后输出是 {"users"=>" 1 2 "}
,如何返回 {"users"=>[1,2]}
这种格式(liquid 语法小白,个人认为需要改动payload
格式)