3

We are getting an error for a component in experience editor.

Error: - XHTML markup is incorrect near field "fld_87182B393C1C4512A1FF76DB6D12EBC0_7B48C6C831FA4C20898328CB063FF744_en_1_6ecd25c3b5a04cde8cb248b6620e78fa_1082_edit".

enter image description here

Below is my code -

{{- linkDetails = (sc_link_info i_item 'Link') -}}
{{if linkDetails.linktype == "external"}}
    <a target='_blank' href="{{ linkDetails.url}}">{{sc_custom i_item "Image" }}</a> 
{{else if linkDetails.linktype == "media"}}
<a target='_blank' href="{{ i_item.Link.media_url }}">{{sc_custom i_item "Image" }}</a> 
{{else}}
<a data-promo='{{-sc_promo i_item-}}' href='{{-i_item.Link.url-}}' data-itemid='{{-i_item.id-}}' data-title='{{-sc_custom i_item "Title"-}}' data-category="{{-i_item.parent.Title-}}">
    {{-sc_custom i_item "Image"-}}
</a> 
{{ end }}

Please guide me to fix this!

2 Answers 2

1

Since you've created custom Scriban extensions like sc_promo and sc_custom and are inserting their returned values into attributes, could you verify that these functions return values as strings when used in attributes?

Alternatively, you can try adding conditions for Experience Editor mode like this:

{{- linkDetails = (sc_link_info i_item 'Link') -}}
{{ if o_pagemode.is_experience_editor }}
    {{ sc_field i_item "Title" }}
{{ else }}
    {{ if linkDetails.linktype == "external" }}
        <a target='_blank' href="{{ linkDetails.url }}">{{ sc_custom i_item "Image" }}</a> 
    {{ else if linkDetails.linktype == "media" }}
        <a target='_blank' href="{{ i_item.Link.media_url }}">{{ sc_custom i_item "Image" }}</a> 
    {{ else }}
        <a data-promo='{{ sc_promo i_item }}' href='{{ i_item.Link.url }}' data-itemid='{{ i_item.id }}' data-title='{{ sc_custom i_item "Title" }}' data-category='{{ i_item.parent.Title }}'>
            {{ sc_custom i_item "Image" }}
        </a> 
    {{ end }}
{{ end }}

Hope this helps! Let me know if you face any issues.

0

It seems you have created custom scriban extension such as sc_promo and sc_custom and inserting the values returned by those extension in the attributes. Can you check the value returned from these functions return string type while using them in attributes.

Also can you add the raw property to set the values in attributes while reading item fields such as below.

data-category="{{-i_item.parent.Title.raw-}}"

Otherwise reading the values without raw property will ingest editable html in the attributes in experience editor mode.

Finally you can make sure the html returned from sc_custom returns valid html. You can find more details for the same here.

https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0365101

Hope this helps!!! Let me know in case you face any issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.