GaryDevenay
GaryDevenay

Reputation: 2415

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.

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).

I seem to recall that the class needs to inherit umbraco.MacroEngines.DynamicNodeContext to be able to access properties in this way.

Are there any alternatives or things that I am missing?

Upvotes: 0

Views: 560

Answers (1)

Digbyswift
Digbyswift

Reputation: 10400

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. To achieve this you will need to pass a DynamicNode object.

Even better, just pass the Node object as a Node parameter. At least this way, you will know exactly what properties you are accessing at compile time.

Upvotes: 1

Related Questions