#Macro in RTE throwing error

1 messages · Page 1 of 1 (latest)

toxic grail
#

I want to use macro with parameters in RTE but when try to get RTE data in graphql playground , it throws error

#

cc @mortal harness

mortal harness
#

Whats the error? And is there any error in the console?

toxic grail
#

value coming null and the only unexpected error occurred coming

mortal harness
#

If you could make a minimal reproduction i could try and troubleshoot it in a couple of weeks. (Im taking a vacation tomorrow)

toxic grail
#

i can provide temporary login

#

let me know when you are back

toxic grail
#

@mortal harness let me know once you are back and will provide you the login

mortal harness
#

Hey i might have a little time in the weekend

toxic grail
#

i have debugged the issue. When i use Macro in RTE, content is coming null

toxic grail
#

this the error

#

StackTrace: " at Umbraco.Cms.Web.Common.Macros.MacroRenderer.<RenderAsync>d__23.MoveNext()\r\n at Umbraco.Cms.Web.Common.Macros.MacroRenderer.<RenderAsync>d__22.MoveNext()\r\n at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.<>c__DisplayClass15_0.<RenderRteMacros>b__1(String macroAlias, Dictionary2 macroAttributes)\r\n at Umbraco.Cms.Infrastructure.Macros.MacroTagParser.ParseMacros(String text, Action1 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()}

toxic grail
#

@mortal harness

mortal harness
#

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

toxic grail
#

Ya i have done that

public CustomRichText(CreatePropertyValue createPropertyValue, IHttpContextAccessor httpContextAccessor) : base(createPropertyValue)
{

    IHtmlEncodedString htmlEncodedString = createPropertyValue.Property.Value<IHtmlEncodedString>(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)

toxic grail
#

@mortal harness 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

mortal harness
mortal harness
toxic grail
toxic grail
# mortal harness Have you tried without using the BasicRichText as a base for the class?

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<IHtmlEncodedString>(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;
}

}

mortal harness
#

In this case which line does it fail on?

toxic grail
#

seems like when macro used, this content is null

mortal harness
#

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

mortal harness
mortal harness
toxic grail
mortal harness