Macro not resolving in page form field

Daniel Main asked on August 28, 2019 22:45

Here is another one.

the macro {% GetSiteSettingsProperty("ClientName") %} works in almost every area of the site except one: the page editing form: screen shot

The output is: Learn about the specific offerings for the {% GetSiteSettingsProperty("ClientName") %}

The issue is this is V12, and I have verified it worked in V9. I am sure it is a code issue, but am unsure where the problem is.

Thanks in advance.

Correct Answer

Brenden Kehren answered on August 29, 2019 06:42

If your text area has macros you need to resolve them in the transformation. By default they are not resolved. So you use something like in this answer.

CMS.MacroEngine.MacroResolver.Resolve(Eval("CustomProperty"));

2 votesVote for this answer Unmark Correct answer

Recent Answers


Mike Wills answered on August 28, 2019 23:54

Hi Dan,

It looks like macros are not being processed when rendering the field. How is the page being rendered? MVC site? Portal Engine template? If the page content is being displayed on an MVC site, it needs to use the MacroResolver API to resolve the macros.

https://docs.kentico.com/k12/macro-expressions/resolving-macros-using-the-api

Mike

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on August 29, 2019 05:47 (last edited on August 29, 2019 05:49)

if you want to get the settings you do not need a custom macro- it should work with settings.Keyname. [See documentation](https://docs.kentico.com/k12/custom-development/creating-custom-modules/adding-cthink ustom-website-settings#Addingcustomwebsitesettings-Gettingsettingvaluesinmacroexpressions)

I dont think your macro is supposed to be resolved in the text area control on the form tab. It can be resolved on an actual page where this navigation copy property is used. Unless you have some resolver that you run on page save.

P.S. I suggest you use Large Text Area (but you need to go to form controls and enable it for page types) instead. It comes with macro editor.

0 votesVote for this answer Mark as a Correct answer

Daniel Main answered on August 29, 2019 17:06 (last edited on August 29, 2019 17:17)

Brendon, you sent me to the correct location, you answer was not techniclay correct for my cercomstance, I realsised that the Article repeater was posiblally useing a transformation, and that apparently all that was needed was to apply a recursive to the macro that rendered the info

{% NavigationCopy|(recursive)true %}

Thanks for pointing me in the correct direction.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 29, 2019 17:13

Things change from 9 to 12 so just because it worked then doesn't mean it will work now. Test your macro in System - Macros.

Some macros wont work in a template either. Maybe try using a static text webpart vs an editable text webpart.

0 votesVote for this answer Mark as a Correct answer

Daniel Main answered on August 29, 2019 17:34

Brenden, I had edited my response apparently after you saw it. thanks again for your assistance.

0 votesVote for this answer Mark as a Correct answer

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