我有一个类(TemplateCompiler),它加载.html文件,并用umbraco节点和导出的属性替换某些值以供外部使用。
using System.Text;
using System.IO;
/// <summary>
/// Template builder gathers the umbraco nodes, gets the appropriate markup and populates it.
/// </summary>
public class TemplateCompiler
{
public static string GetCode(dynamic performance)
{
//loadTemplate is a function defined elsewhere
var template = loadTemplate("Main.html");
template.Replace("###BODY###", performance.bodyContent);
}
}
我是否可以像这样的方式访问性能对象的umbraco属性(性能类型为umbraco.presentation.nodeFactory.Node)。
我似乎记得该类需要继承umbraco.MacroEngines.DynamicNodeContext才能以这种方式访问属性。
我缺少任何替代品或事物吗?
答案 0 :(得分:1)
您的课程不需要为此继承任何内容。但是,如果要在动态参数中传递Node
对象,则它将不会像您期望的那样运行。为此,您需要传递一个DynamicNode
对象。
更好的是,只需将Node
对象作为Node
参数传递即可。至少通过这种方式,您将确切知道在编译时访问的属性。