Dynamically add current page URL to href

Dominic Carvalho asked on August 15, 2018 23:06

Hey, I am trying to dynamically add add a url to an href attribute in the head tag. I tried using {%CurrentDocument.NodeAliasPath%} in the href="" but it doesn't render the full url of the current page.

Is their another way to do this to get the full URL of the current page?

Any help will be greatly appreciated.

Kind Regards Dominic

Recent Answers


Peter Mogilnitski answered on August 16, 2018 00:52 (last edited on December 10, 2019 02:31)

{%CurrentDocument.AbsoluteURL|(identity)GlobalAdministrator%} should do that. For head tag you can use html head code web part.

0 votesVote for this answer Mark as a Correct answer

Dominic Carvalho answered on August 16, 2018 08:56

Hey Peter Mogilnitski, Thanks for the reply. I tried that and it gives me the full url of the document but I have one layout that is dynamically being shared across a bunch of alias' so that absolute url gives me the same url for all those different pages.

I have a DM_Layout -> A bunch of different pages that dynamically gets posted and renders a new page using an alias.

So I would need that full alias page instead of just the absolute URL.

The Absolute URL just gives me http://sitename/dm-pages/dm_games/" for every dynamic page.

Hope I've explained that well enough :/

Kind Regards Dominic

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on August 16, 2018 10:11 (last edited on December 10, 2019 02:31)

Use {% CurrentDocument.NodeAliasPath |(identity)GlobalAdministrator%} then :)

0 votesVote for this answer Mark as a Correct answer

Dominic Carvalho answered on August 16, 2018 10:30

Hey Jan Hermann, That only renders the last part of the url ? e.g : href="/promotions" where I need the current site and the node alias path.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on August 16, 2018 10:34 (last edited on December 10, 2019 02:31)

That should be enough - browsers always prepend current domain to it. Alternatively you can add ~ to let our output filter to resolve the url: ~{% CurrentDocument.NodeAliasPath |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 16, 2018 14:40 (last edited on December 10, 2019 02:31)

If Jan's solution of adding the ~ isn't enough for you, then try getting the domain dynamically like so:

{%domain%}{%CurrentDocument.NodeAliasPath|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

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