Visibility Macro in Static HTML web part

Ryan Elliott asked on March 5, 2019 19:01

Currently have a Static HTML webpart and the content section is set to include a widget. Widget is a modal popup window to sign up for a newsletter.

The Visibility section of the webpart is currently using a macro to hide the modal popup if the URL contains specific words, but doesn't seem like it's working.

Visibility macro - {% (CurrentUrl.Contains("home")) || (CurrentUrl.Contains("someOtherTextHere")) #%}

Correct Answer

Rui Wang answered on March 5, 2019 19:26

Not sure if that error is related to this macro or not, but do these test one at a time and check if you see macro error in event long.

use {% CurrentUrl %} only and see if you get the URL

use {% CurrentUrl.Contains("home") %} only and see if you get True/False

0 votesVote for this answer Unmark Correct answer

Recent Answers


Rui Wang answered on March 5, 2019 19:08

{% CurrentUrl.Contains("AAA") || CurrentUrl.Contains("BBB") #%} works for my visibility. Can you check Event Log to see if there are any errors?

Also, put that macro into HTML Envelop field of the web part and see if you get True/False value.

0 votesVote for this answer Mark as a Correct answer

Ryan Elliott answered on March 5, 2019 19:19

I do get an error in the event log.

Message: A potentially dangerous Request.Path value was detected from the client (&).

Exception type: System.Web.HttpException Stack trace: at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)

And when I put that macro in the Content Before section of the HTML Envelope, nothing gets returned within the web part.

0 votesVote for this answer Mark as a Correct answer

Ryan Elliott answered on March 5, 2019 19:41

I took the macro out, and unchecked the visibility checkbox, apply change then save and close, then save the entire page, the modal popup static HTML webpart still shows up.

I also still have the same error in the event log without the visibility macro - something else is definitely wrong

I then changed the Visible field back to a macro, and used {% CurrentDocument.AbsoluteURL.Contains("textHere") %} - modal popup is still visible

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on March 5, 2019 21:18

There maybe some JS issue in this case. You may need to clear cache and try to load the page again (if you are using Chrome). Typical "A potentially dangerous Request" error are related to JS as well.

0 votesVote for this answer Mark as a Correct answer

Ryan Elliott answered on March 25, 2019 19:26

This did end up getting worked out. There was also an issue with the current cookie on the site.

0 votesVote for this answer Mark as a Correct answer

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