Ascx macro for page's alias url

Targutai Yesugei asked on October 4, 2017 11:32

Hello!

Still stucked with all these macros, and now i can't get object's alias url. I tried <%# Eval("AliasURLPath") %> but it doesn't work and returns empty string(i checked, that object do have aliases).

What should i use in my situation? Thanks in advance.

Recent Answers


Trevor Fayas answered on October 4, 2017 14:11

If you are using ascx transformation, you need to use the given transformation methods Kentico provided, such as GetDocumentUrl()

https://docs.kentico.com/k10/developing-websites/loading-and-displaying-data-on-websites/writing-transformations/reference-transformation-methods

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 4, 2017 14:37

Do you want the document's actual live path? If you can use one of several approaches:

<%# GetDocumentUrl() %> - gets documents URL
<%# GetDocumentUrl(Eval("DocumentID")) %> - gets documents URL if a linked page
<%# Eval("NodeAliasPath") %> - gets the documents node alias path, which could be different from the actual URL but in most cases is not.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on October 4, 2017 17:26

You should also understand the difference between a ASCX method (used in ASCX transformation or layout) vs a Macro (used in HTML/Text)

0 votesVote for this answer Mark as a Correct answer

Targutai Yesugei answered on October 4, 2017 19:04

Actually, i need alias url, which i set in urls tab. Not NodeAliasPath, but alias url.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on October 4, 2017 19:20 (last edited on December 10, 2019 02:31)

So you are talking about URL alias of a page, which is an array. If you are going to use Macro, it would be {% CurrentDocument.Aliases[0].AliasURLPath |(identity)GlobalAdministrator%} for the first alias.

0 votesVote for this answer Mark as a Correct answer

Targutai Yesugei answered on October 5, 2017 06:54 (last edited on December 10, 2019 02:31)

I'm using it in transformation and i was told that this macro should be inside <%%>.

I tried this earlier and it returns {% CurrentDocument.Aliases[0].AliasURLPath |(identity)GlobalAdministrator%}.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on October 5, 2017 15:34 (last edited on December 10, 2019 02:31)

In transformations, you can do either text/xml (using {% %} and macros) or ascx, you cannot do both (except for if you call hte macro resolver from ascx...but that's besides the point).

Set the transformation type to text/xml and try {% CurrentDocument.Aliases[0].AliasURLPath |(identity)GlobalAdministrator%} or something close to that.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on October 5, 2017 15:36

Are you using the transformation in a repeater and trying to get the alias from each child node? Because the above will only get the alias parent node when it's used in a repeater list view.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on October 5, 2017 16:02 (last edited on December 10, 2019 02:31)

The ASCX for getting the first URL alias for each child in a repeater list is <%# CMS.DocumentEngine.DocumentAliasInfoProvider.GetDocumentAliases().WhereEquals("AliasNodeID", Eval("NodeID")).First().AliasURLPath %>

@Trevor, I tried that macro {% Documents[NodeAliasPath].Aliases[0].AliasURLPath |(identity)GlobalAdministrator%} before and it doesn't exist

0 votesVote for this answer Mark as a Correct answer

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