Macro in RTE throwing error
# help-with-umbraco
n
I want to use macro with parameters in RTE but when try to get RTE data in graphql playground , it throws error
cc @Nikcio
n
Whats the error? And is there any error in the console?
n
value coming null and the only unexpected error occurred coming
n
If you could make a minimal reproduction i could try and troubleshoot it in a couple of weeks. (Im taking a vacation tomorrow)
n
i can provide temporary login
let me know when you are back
@Nikcio let me know once you are back and will provide you the login
n
Hey i might have a little time in the weekend
n
i have debugged the issue. When i use Macro in RTE, content is coming null
this the error
StackTrace: " at Umbraco.Cms.Web.Common.Macros.MacroRenderer.d__23.MoveNext()\r\n at Umbraco.Cms.Web.Common.Macros.MacroRenderer.d__22.MoveNext()\r\n at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.<>c__DisplayClass15_0.b__1(String macroAlias, Dictionary`2 macroAttributes)\r\n at Umbraco.Cms.Infrastructure.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback)\r\n at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.RenderRteMacros(String source, Boolean preview)\r\n at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.Convert(Object source, Boolean preview)\r\n at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview)\r\n at Umbraco.Cms.Core.Models.PublishedContent.PublishedPropertyType.ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview)\r\n at Umbraco.Cms.Core.PublishedCache.PublishedElementPropertyBase.GetValue(String culture, String segment)" TargetSite: {Void MoveNext()}
@Nikcio
n
From the stacktrace i can only see it failing inside Umbraco and not in the UHeadless code. Is there any more to the stacktrace?
You could also try and copy the BasicRichText class code so you can step through that in your own application
n
Ya i have done that public CustomRichText(CreatePropertyValue createPropertyValue, IHttpContextAccessor httpContextAccessor) : base(createPropertyValue) { IHtmlEncodedString htmlEncodedString = createPropertyValue.Property.Value(createPropertyValue.PublishedValueFallback, createPropertyValue.Culture, createPropertyValue.Segment, createPropertyValue.Fallback); if (htmlEncodedString != null) { Value = htmlEncodedString?.ToHtmlString(); SourceValue = createPropertyValue.Property.GetSourceValue(createPropertyValue.Culture)?.ToString(); } var value = createPropertyValue.Property.GetValue().ToString(); string pattern = "((?:src)[\\s]*?)(?:\\=[\\s]*?[\\\"\\\'])[\\/*\\\\*]?(?!..+[s]?\\:[\\/]*)(.*?)(?:[\\s\\\"\\\'])"; var reg = new Regex(pattern, RegexOptions.IgnoreCase); string prefix = string.Format("{0}://{1}/", httpContextAccessor.HttpContext.Request.Scheme, httpContextAccessor.HttpContext.Request.Host.Value); var absoluteValue = reg.Replace(value, "$1=\"" + prefix + "$2\""); HTMLValue = absoluteValue;
its same error Value can't be null ( parameter conten)
@Nikcio i also found issue with Preview when there multisite setup
e.g.
and domain set on home page like /au , /in
now when we use routeMode: CACHE_OR_ROUTING for preview it throwes error when using ContentByAbsoluteRoute but works for ContentbyId
n
Have you tried without using the BasicRichText as a base for the class?
n
checking
n
Do you have the same problem if you just use ROUTING?
n
no but when using routing unpublished content not coming
I am not using BasicRichText as class. This is my full class using HotChocolate; using Microsoft.AspNetCore.Http; using Nikcio.UHeadless.Base.Basics.EditorsValues.RichTextEditor.Models; using Nikcio.UHeadless.Base.Properties.Commands; using Nikcio.UHeadless.Base.Properties.Models; using System.Text.RegularExpressions; using Umbraco.Cms.Core.Strings; public class CustomRichText : PropertyValue { public string HTMLValue { get; set; } public virtual string? Value { get; set; } public virtual string? SourceValue { get; set; } public CustomRichText(CreatePropertyValue createPropertyValue, IHttpContextAccessor httpContextAccessor) : base(createPropertyValue) { IHtmlEncodedString htmlEncodedString = createPropertyValue.Property.Value(createPropertyValue.PublishedValueFallback, createPropertyValue.Culture, createPropertyValue.Segment, createPropertyValue.Fallback); if (htmlEncodedString != null) { Value = htmlEncodedString?.ToHtmlString(); SourceValue = createPropertyValue.Property.GetSourceValue(createPropertyValue.Culture)?.ToString(); } var value = createPropertyValue.Property.GetValue().ToString(); string pattern = "((?:src)[\\s]*?)(?:\\=[\\s]*?[\\\"\\\'])[\\/*\\\\*]?(?!..+[s]?\\:[\\/]*)(.*?)(?:[\\s\\\"\\\'])"; var reg = new Regex(pattern, RegexOptions.IgnoreCase); string prefix = string.Format("{0}://{1}/", httpContextAccessor.HttpContext.Request.Scheme, httpContextAccessor.HttpContext.Request.Host.Value); var absoluteValue = reg.Replace(value, "$1=\"" + prefix + "$2\""); HTMLValue = absoluteValue; } }
n
In this case which line does it fail on?
seems like when macro used, this content is null
n
That call ".Value" is using the Umbraco source code it's not the command having content as null but somewhere in the Umbraco source code the problem is
n
hmmm
Similarly I think it might be the call to this in the source code that gets your preview to fail: https://github.com/umbraco/Umbraco-CMS/blob/2221c4f1c719f072d660df1a9e16b2fbce3fc17b/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs#L27
n
preview is definitely due to multi site
n
n
if remove multi site then it work
9 Views