Resolve Macro within Transformations

John Fu asked on December 10, 2014 14:50

I'm trying to resolve a macro inside a transformation but it doesn't seem to work. Basically, I'm trying to get at the current transforming node's parent's DrawerName field. Any ideas?

<dd class="drawerMenu" 
data-menu="<%# CMS.MacroEngine.MacroResolver.GetInstance().ResolveMacros("{% DocumentContext.CurrentDocumentParent.DrawerName %}") %>-<%# Eval("DrawerName") %>">
  <span class="drawerMenu-title">
    <span class="drawerMenu-title--text"><%# Eval("DrawerName") %></span>
    <span class="drawerMenu-arrow fa"></span>
  </span>
</dd>

Recent Answers


Brenden Kehren answered on December 10, 2014 15:15

You can use <%# CurrentDocument.Parent.GetValue("DrawerName") %> to get the document you are navigating to parent info. Otherwise you can use (I believe this is correct syntax) <%# Documents[Eval("NodeAliasPath")].Parent.GetValue("DrawerName") %> to get the value of the document being rendered.

1 votesVote for this answer Mark as a Correct answer

John Fu answered on December 10, 2014 15:21

Hi Brenden,

Neither of them worked.
The 1st method returned Object refernce not set to an instance of an object. The 2nd method returned an error saying "Documents" does not exist in the current context.

Any ideas?

0 votesVote for this answer Mark as a Correct answer

John Fu answered on December 10, 2014 15:22

I'm using Kentico 8 by the way.

0 votesVote for this answer Mark as a Correct answer

John Fu answered on December 10, 2014 15:59

Worked it out. A bit long winded for my liking. Anyone want to simplify this?

<%# CMS.DocumentEngine.DocumentHelper.GetDocument(int.Parse(Eval("NodeParentID").ToString()), new CMS.DocumentEngine.TreeProvider())["DrawerName"] %>

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 10, 2014 16:54

The first one is correct, is your column name spelled correctly or that your parent document type has that field name?

The second one would need to be wrapped in the macro resolver and remove the "Eval("")" from the NodeAliasPath, sorry, my mistake.

0 votesVote for this answer Mark as a Correct answer

John Fu answered on December 11, 2014 01:05

So what is the code for the macro resolver? My code now looks like this but it doesn't produce any output.

<%# CMS.MacroEngine.MacroResolver.GetInstance().ResolveMacros("{% Documents[NodeAliasPath].Parent.GetValue(\"DrawerName\") %}") %>

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 11, 2014 08:16

Hi John,

Maybe an important note - macros are not supported in ASCX transformation, only txt and HTML transformations are supported.

In ASCX transformation you can use the SCRIPT tags and use the API or you need to create a custom transformation method.

Best regards,
Juraj Ondrus

0 votesVote for this answer Mark as a Correct answer

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