以 Direct Usage Sample 的形式使用 Spark 时是否可以使用主布局?我已经尝试在我的布局中使用我的主布局与调用布局在同一文件夹中,我还尝试在下面的代码中将主布局作为模板添加到 SparkViewDescriptor?
public class DefaultMessageBuilder : MessageBuilder
{
private readonly ISparkViewEngine _engine;
public DefaultMessageBuilder()
{
var settings = new SparkSettings()
.SetDebug(true)
.SetPageBaseType(typeof(TemplateBase))
.AddNamespace("System.Collections.Generic");
var templates = new VirtualPathProviderViewFolder("~/Templates");
_engine = new SparkViewEngine(settings) { ViewFolder = templates };
}
public override void Transform(string templateName, object data, TextWriter output)
{
var descriptor = new SparkViewDescriptor()
.AddTemplate("Master.spark")
.AddTemplate(templateName + ".spark");
var view = (TemplateBase)_engine.CreateInstance(descriptor);
try
{
view.ViewData = new ViewDataDictionary(data);
view.RenderView(output);
}
finally
{
_engine.ReleaseInstance(view);
}
}
}