Umbraco.Forms.Issues icon indicating copy to clipboard operation
Umbraco.Forms.Issues copied to clipboard

Macros fails in RTE field type

Open skttl opened this issue 2 years ago • 2 comments

Bug summary

It seems like Macros doesn't work in the new RTE field type (version 10.1.0). The GetMacroResultAsHtmlForEditor API call fails with the following response:

{"ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":null,"StackTrace":null}

And in the frontend rendering, it doesn't convert the markup code, to the actual markup output. I just get this:

<div class="umb-macro-holder Button umb-macro-mce_1 mceNonEditable loading"><!-- <?UMBRACO_MACRO macroAlias="Button" text="Se vedtægter" linkUrl="/vedtaegter" /> --><ins>Macro alias: <strong>Button</strong></ins></div>

Steps to reproduce

  • Create a macro, you can try just creating one from the Empty snippet. Enable "use in Rich Text Editor".
  • Add an RTE field to a form, and insert the Macro
  • Error messages will show in the backoffice saying "Failed to retrieve macro result for macro"
  • Save it anyway
  • In the frontend the macro placeholder content is not replaced with the actual macro output.

Expected result

I would expect it to not throw errors, and the frontend should replace the placeholder with the actual content.

skttl avatar Sep 06 '22 07:09 skttl

Yes, this is above and beyond what I saw the use case for this feature to be - which is really just an ability to do a bit more than the current "Title and description" field (i.e. add support for formatted text, add links to terms and conditions or privacy policies, etc.).

I don't see any easy resolution to this - unless you have any suggestions? - and so would recommend that macros aren't used in this context.

It is possible to configure a custom RTE to use for this field type - see details here - and by doing that you can prevent editors trying to use this feature.

AndyButland avatar Sep 08 '22 09:09 AndyButland

Yes, it would probably require some macro changes in Core too. I suspect it fails, because it needs a node context, which the form doesn't provide.

I was going to use a macro to add a call to action button with a picked icon. This requires a bit of markup, that I don't want to editor to handle themselves.

I've fixed it for now, by having a format, that I manipulate using HtmlAgilityPack instead, and then the icon is just a default one.

skttl avatar Sep 08 '22 10:09 skttl