Hierarchical Viewer and Page Selector

Aaron Fickes asked on October 10, 2018 16:14

Question: How do I get the url of a Page Selector field in an object at depth 1 or more from an HTML/XML Transformation?

Setup:

Using Kentico 11

I currently have a Page Object with a child LinkList custom object with children of InternalLink or ExternalLink objects. InternalLink, ExternalLink, and LinkList are all Content Only page types. InternalLinks object uses a Page Selector field ("LinkUrl") and ExternalLinks uses a URL Selector field (also "LinkUrl"). Since the client tends to move pages, a Page Selector field was chosen to maintain a link.

The Url Selector works just fine as it saves the URL as a string, but since the Page Selector saves a GUID (either as GUID or string) there does not seem to be a way to convert it back out. I see that GetDocumentByGUID needs a object GUID and object NodeAlias. However, that page selector can choose one of many page types across the website.

The item transformation for the links is as follows: (LinkType is a field on both objects, that is hidden for edit and default to specific text.)

{%if(LinkType=="Internal") { %}
<li class="{% LinkType %}">
  <a href="{% GetDocumentUrlByGUID(LinkUrl) %}" {% if(OpenNewWindow){ %} target="_blank" {% } #%}>
    {% LinkText %}
    <svg class="icon"><use xlink:href="#single_arrow_dark"/></svg>
  </a>
</li>
{% } #%}

{% if(LinkType=="External") { %}
<li class="{% LinkType %}">
  <a href="{% LinkUrl %}" {% if(OpenNewWindow){ %} target="_blank" {% } #%}>
    {% LinkText %}
    <svg class="icon"><use xlink:href="#single_arrow_dark"/></svg>
  </a>
</li>
{% } #%}

I've tried most of what is in the docs, but nothing seems to work as I just get errors in the EventViewer.


Error while evaluating expression: Transformation.GetDocumentUrlByGUID(LinkUrl) |(identity)GlobalAdministrator|(hash)4f00eaad761d8055468f6fcdecd55f7294825c9894aea242b86837ca63b87f4a CMS.MacroEngine.EvaluationException: Exception occured while evaluation of the expression ' Transformation.GetDocumentUrlByGUID(LinkUrl) |(identity)GlobalAdministrator|(hash)4f00eaad761d8055468f6fcdecd55f7294825c9894aea242b86837ca63b87f4a': Specified method is not supported. ---> System.NotSupportedException: Specified method is not supported.


Error while evaluating expression: GetDocumentUrlByGUID(LinkUrl) CMS.MacroEngine.EvaluationException: Exception occured while evaluation of the expression ' GetDocumentUrlByGUID(LinkUrl) ': Specified method is not supported. ---> System.NotSupportedException: Specified method is not supported.


Error while evaluating expression: GetDocumentUrlId(LinkUrl) CMS.MacroEngine.EvaluationException: Exception occured while evaluation of the expression ' GetDocumentUrlId(LinkUrl) ': Method 'GetDocumentUrlId' for object of type 'System.String' not found, please check the macro or the method declaration.


EDIT: After no comments after a few days, I had to move on so I used a custom macro instead.

[MacroMethod(typeof(string), "Return the Relative URL of a Document GUID", 1)]
[MacroMethodParam(0, "GUID", typeof(string), "The GUID of the Document.")]
public static string GetGuidUrl(EvaluationContext context, params object[] parameters)
{

    string param_guid = ValidationHelper.GetString(parameters[0], "");
    Guid guid = new Guid(param_guid);
    TreeProvider tp = new TreeProvider();
    TreeNode tn = tp.SelectSingleNode(guid, context.Culture, SiteContext.CurrentSiteName);
    return tn.RelativeURL;

}

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