Using macros to get data from a document via nodealiaspath in an email template

Kentico User asked on February 3, 2016 17:23


In my CMS tree, within a folder, I have a custom page type with two fields: Title and Description. Is it possible to get the value of the "Description" value using the NodeAliasPath within an email template or an AutoResponder in a bizform? The email template will be sent using a custom form handler after the the biz form is populated, if a bizform autoresponder cannot be used.

Recent Answers

Joshua Adams answered on February 3, 2016 18:51

I see two different approaches here:

1)If the nodealiaspath is the current document, add a new field that captures the current nodealiaspath with a macro using the currentdocument object, that way you can use that in your email template.

2)If the nodealiaspath that you want isn't the document where the form is submitted, create a custom macro method that fetches the appropriate path.

0 votesVote for this answer Mark as a Correct answer

Kentico User answered on February 4, 2016 16:19 (last edited on December 10, 2019 02:30)


I created this macro but it doesn't seem to work.

    // Makes all methods in the 'CustomMacroMethods' container class available for string objects
[assembly: RegisterExtension(typeof(CustomMacroMethods), typeof(string))]
// Registers methods from the 'CustomMacroMethods' container into the "String" macro namespace
[assembly: RegisterExtension(typeof(CustomMacroMethods), typeof(StringNamespace))]
public class CustomMacroMethods : MacroMethodContainer
    [MacroMethod(typeof(string), "Get the answer detail text to email", 2)]
    [MacroMethodParam(0, "param1", typeof(string), "Partial node alias path to question")]
    [MacroMethodParam(1, "param2", typeof(string), "Second part of the string completes the node alias path with the answer to email.")]
    public static object GetAnswer(EvaluationContext context, params object[] parameters)
        switch (parameters.Length)
            case 2:
                string questionPath = ValidationHelper.GetString(parameters[0], "");
                string answer = ValidationHelper.GetString(parameters[1], "");
                string nodeAliasPath = string.Format("{0}/{1}", questionPath, answer);

                CMS.DocumentEngine.TreeProvider tp = new CMS.DocumentEngine.TreeProvider();
                TreeNode node = tp.SelectSingleNode(CMS.SiteProvider.SiteContext.CurrentSiteName, nodeAliasPath, "");
                if (node != null)
                    return node.GetStringValue("AnswerExplanation", "");
                    return string.Empty;
                throw new NotSupportedException();

I use it in my autoresponder as follows

{% "/Take-the-Test/TakeTheTest/Question1".GetAnswer($$value:Question1$$) |(identity)GlobalAdministrator%}

I get nothing back. Any ideas?

0 votesVote for this answer Mark as a Correct answer

Kentico User answered on February 4, 2016 17:26

I just realized I cannot do what I am trying to do above because the macro is resolved before the string "$$value:Question1$$" gets resolved.

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on February 4, 2016 21:08

Shouldn't you call your macro with 2 parameters?

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.