[英]Umbraco get node properties from inside a class
I have a class (TemplateCompiler) which loads in .html files, and replaces certain values with properties from umbraco nodes and exports for an external use. 我有一个类(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);
}
}
Can I possibly access the performance object's umbraco properties in a fashion like this (performance is of type umbraco.presentation.nodeFactory.Node). 我能否以这种方式(性能类型为umbraco.presentation.nodeFactory.Node)访问性能对象的umbraco属性。
I seem to recall that the class needs to inherit umbraco.MacroEngines.DynamicNodeContext to be able to access properties in this way. 我似乎记得,该类需要继承umbraco.MacroEngines.DynamicNodeContext才能以这种方式访问属性。
Are there any alternatives or things that I am missing? 是否有其他选择或我缺少的东西?
Your class doesn't need to inherit anything for this to work. 您的课程无需继承任何内容即可正常工作。 However, if you are passing a
Node
object in a dynamic parameter, it won't behave as you are expecting. 但是,如果要在动态参数中传递
Node
对象,则它的行为将与您期望的不同。 To achieve this you will need to pass a DynamicNode
object. 为此,您将需要传递
DynamicNode
对象。
Even better, just pass the Node
object as a Node
parameter. 更好的是,只需将
Node
对象作为Node
参数传递。 At least this way, you will know exactly what properties you are accessing at compile time. 至少通过这种方式,您将确切地知道在编译时正在访问哪些属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.