我正在尝试使用 Scriban 模板引擎来支持多循环。例如
string bodyTextSub = "{{ for service in services }} ServiceName: {{ service }} {{ end }}" +
"{{ for subservice in subServiceList }} SubServiceName: {{ subservice }} {{ end }}";
List<string> subServiceList = new List<string>
{
"PingSubService",
"UrlSubService"
};
Dictionary<string, List<string>> serviceDictionary = new Dictionary<string, List<string>>()
{
{"emailContent", subServiceList},
{"mailContent", subServiceList}
};
var template2 = Template.Parse(bodyTextSub);
var result2 = template2.Render(new { services = serviceDictionary });
Console.WriteLine(result2.ToString());
我得到的输出像
ServiceName: {key: emailContent, value: [PingSubService, UrlSubService]}
我希望基于我们应该在子服务中循环的键,但它没有发生。任何人都可以帮助我吗?
我的第二个问题是 Scriban 模板引擎支持嵌套循环吗?提前致谢