使用DotLiquid包含方法时如何获取文件路径?

时间:2017-06-05 10:29:17

标签: dotliquid

我创建了Include方法,如下面的代码。

如下所示的products.liquid

{% include product-list-item %}

如下所示的包含方法:

public class IncludeFileSystem : IFileSystem
{
    public string ReadTemplateFile(Context context, string templateName)
    {
        string themesLocalPath = "";
        var templatePath = LiquidTemplateHelper.ResolveTemplatePath(templateName, themesLocalPath);
        return LiquidTemplateHelper.ReadTemplateByPath(templatePath);
    }
}

但是对于不同的用户,他们从文件中加载不同的“product-list-item”。 如何设置get并设置“themesLocalPath”值?

1 个答案:

答案 0 :(得分:0)

使用文件系统有两种方法:

  1. 如果要全局设置,请设置Template.FileSystem
  2. 如果您要为每次渲染设置,请在renderParameters.Registers["file_system"]来电中设置Template.Render。例如,这允许您为每个用户创建自定义文件系统的差异实例。