Link/Button Web Part Link URL Macro Property

Kwabena Adu asked on March 26, 2014 13:03

I am trying to set the Link URL Property from a Macro as follows: {%URLHelper.AddParameterToUrl(URLHelper.CurrentURL, "sort", "random").ToString()#%}

It seems it is never resolved, as the link renders on the page without a "href". The code within the braces will work fine on an ASPX page.

What I want to achieve is to add a url to the current url and set is as the href of the link. Is there a simple way to do it via the portal engine?

Thanks.

Correct Answer

Brenden Kehren answered on March 26, 2014 23:00

If you are attempting to use the code you provided as a macro within the webpart, it will not work because URLHelper is not available as a macro. So yes, it does make a difference where you are using the code. Not all methods/functions are available as macros. It is a method that can be accessed in code behind but has not been exposed as a macro.

You might look into using what I suggested, create a custom macro, or looking into using document aliases with parameters.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on March 26, 2014 13:49

Where are you creating this link? Transformation? Editable Text Webpart?

One way you could do this would be to create the link manually <a href='<%# CMSContext.CurrentDocument.NodeAliasPath + "?sort=random" %>'>Link</a>

1 votesVote for this answer Mark as a Correct answer

Kwabena Adu answered on March 26, 2014 14:24

Hi Brenden, Thanks for you quick response. I am doing it in a link/button webpart. The answer you gave may also work but the page can also have some additional parameters in the url. That is why I prefer to use the Add Parameter method. Do you have an example with the Add Parameter method? (URLHelper.AddParameterToUrl) regardless of the control. I am using the portal engine.

0 votesVote for this answer Mark as a Correct answer

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