Front-end not handling macros consistently, but the cms desk back-end does

Jason Delaplain asked on April 20, 2017 00:24

I've been fighting with an issue for quite awhile, and finally got to a point where I started hard coding macros so I can see the values being outputted.

What I found (with my Dev instance) is that the CMS Desk is handling a Macro statement correctly, but the values of the same macros on the front-end are not.

For example: I have an editable text web part, where I don't want to display it if the ViewMode is LiveSite and the content is empty. After many variations of a macro statement, I found that in "EditLive" or "LiveSite" view modes, it was showing the webparts content of a string "Test", but the boolean to check that web part, "!string.isnullorwhitespace(editabletext)" showed False on the front-end and True in the CMS Desk Design or Preview modes.

I played with some caching settings and nothing made a difference (I set them back after testing).

AM I missing something? I have spent way too much time to add a simple macro statement to a web part for the visibility function.

Correct Answer

Juraj Ondrus answered on April 20, 2017 16:10

Hi,
We had also an email communication with Jason and it turned out that the issue was that you need to get the editable text content like this
on the same page, you should be using macro like this:

 {% CurrentDocument.DocumentContent["editabletextID"] #%}

If you want to check the content of a different page, you should be using macro like this (this sample is to get the content from a root page):

{%Documents["/"].DocumentContent["editabletextID"] #%}

So, the macro that worked for Jason looks like this:
{% (!String.IsNullOrWhiteSpace(Documents["/"].DocumentContent["editabletextID"])) || (ViewMode != "LiveSite" && ViewMode != "Preview") #%}

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on April 20, 2017 03:07

What version are you on?

0 votesVote for this answer Mark as a Correct answer

Jason Delaplain answered on April 20, 2017 04:13

We're currently in 9.34

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 20, 2017 14:49

  • When you check the event log are you seeing macro errors?
  • In your different environments is the web.config key CMSHashStringSalt the same in all environments?
  • Have you tried to resign all your macros?
  • Are the macros custom or the built-in ones?

Lastly, what does your macro look like? Here's an example of what I use:

{% (ViewMode != "LiveSite") || (editabletextwebpartname != null && editabletextwebpartname.Trim() != "") @%}

0 votesVote for this answer Mark as a Correct answer

Jason Delaplain answered on April 20, 2017 16:17

It all makes sense now, ha. Thanks for the help guys.

0 votesVote for this answer Mark as a Correct answer

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