Getting expressions to work in Metadata MVC

Graham Mott asked on July 22, 2019 13:48

I have a page type that can inherit it's metatitle from the root page.

The root page's metatitle is "{%DocumentName%}"

I am using page.GetInheritedValue("DocumentPageTitle").ToString() which only returns it back as a string rather than expanding the expression.

Any ideas how I would go about getting the expanded inherited response?

Correct Answer

Eric Dugre answered on July 24, 2019 22:01

If you're missing the proper context for resolving macros in the MVC application, you can use SetNamedSourceData() to register data. I would change the macro to something like {%CurrentDocument.DocumentName|(identity)GlobalAdministrator%}, then you can resolve the macro like this:

var resolver = MacroContext.CurrentResolver;
resolver.SetNamedSourceData("CurrentDocument", node);
var title = resolver.ResolveMacros(node.DocumentPageTitle);
2 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on July 22, 2019 14:47

It returns the macro that has to be resolved calling appropriate API.

But in your particular case macro would resolve into current document name, so I recommend you to get it directly from API.

0 votesVote for this answer Mark as a Correct answer

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