GetDocumentUrl(PageField)

Brendon McCarthy asked on March 25, 2015 20:50

As documented here, https://docs.kentico.com/display/K82/Reference+-+Transformation+methods, I am trying what I would think is a very simple task. I have a text field with a form control of "Page selector" on the Event page type. In my transformation, I want to generate the Page url.

{% GetDocumentUrl(PageUrlField) %}

PageUrlField is represented as a GUID string, i.e. AF3BC4C6-0EF2-4287-8229-463ACDCEC1A3. The documentation states that "You can optionally specify the page using a page ID." Always though when passing the value of the PageUrlField into the GetDocumentUrl method, an empty string is returned. I've also tested via the System > Macro > Console and same result: nothing.

Note that GetDocumentUrl() with no parameters works correctly.

What am I blindly missing? This should be simple, common right?

Recent Answers


Brenden Kehren answered on March 25, 2015 22:23

If you want to use the GUID, you need to use this signature <%# GetDocumentUrl(Eval("NodeGUID"), Eval("NodeAlias")) %>

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on March 25, 2015 22:29

@Brenden - Only a single value is returned from the "Page selector" control, the GUID mentioned. Whether this is a NodeGUID or not I'm unsure. There is no NodeAlias or is this optional?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 26, 2015 11:52

When using the GUID, the alias is NOT optional. If using the document ID then all you need is that ID. I typically use a URL selector, by far the easiest to use in my opinion all around.

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on March 26, 2015 21:26

What does the Page selector control type return? It must not be the DocumentId, my guess is it is the NodeId.

The Url Selector could work, but it introduces another issue. The field is being used to redirect the user to another page. The Event page however exists on multiple sites as a linked-page. The redirect page may not exist on another site, therefore it needs the absolute url. The Url Selector only seems to return the relative url. Unchecking the "Use relative url" box does nothing (it stays checked on refresh).

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 26, 2015 23:46 (last edited on March 26, 2015 23:47)

This will get your absolute url

<%# URLHelper.GetAbsoluteUrl(GetDocumentUrl(Eval("NodeGUID"), Eval("NodeAlias"))) %>

I believe you can also specify a site name or site ID with the GetAbsoluteUrl() method to get that domain information as well.

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on April 3, 2015 00:30

The problem is that I cannot find how to get the NodeAlias, SiteId or SiteName of the original page. This page is cross-linked and all the macros that would provide this information about the page return values for the current site/domain, not the original site/domain.

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on April 8, 2015 23:17

I've not found a way to get the SiteId of the PageUrlField if using the URL selector as the required parameters are not returned, only the Url, i.e. ~/name-of-page. All the Kentico methods appear to require the NodeAlias and/or NodeGUID and/or SiteId and/or another combination of values.

For my specific use case though, I've been able to get the NodeLinkedNodeSiteID from the CurrentDocument. This makes an assumption that the value of the PageUrlField is within the same site as the non-linked page.

{% GetAbsoluteUrlBySiteId(PageUrlField, CurrentDocument.NodeLinkedNodeSiteID) %}

Still looking for a solution to get the Absolute Url from both the URL Selector or Page Selector control types when the value is to a linked-page.

0 votesVote for this answer Mark as a Correct answer

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