我正在使用DotLiquid模板引擎并尝试在模板中访问字典值.我已经传递给模板这个drop:
public class SomeDrop : Drop
{
public Dictionary<string, object> MyDictionary {get; set;}
}
var someDropInstance = SomeDrop
{
MyDictionary = new Dictionary<string, object> {{"myKey", 1}}
}
Template.NamingConvention = new CSharpNamingConvention();
var preparedTemplate = Template.Parse(template);
var templateOutput = preparedTemplate.Render(Hash.FromAnonymousObject(new { @this = someDropInstance }));
Run Code Online (Sandbox Code Playgroud)
在模板我不能访问的myKey值
{{ this.MyDictionary.myKey }}
既不
{{ this.MyDictionary['myKey'] }}