DEV Community

Daniel Gomez
Daniel Gomez

Posted on

1 1 1 1

Sitecore Experience Editor Tip to show instructions to Content Authors

When creating components in Sitecore, we try to make them as manageable from the Experience Editor as possible, but there are times when we have to give additional instructions so that the Content Author can use the placeholders properly, add options, modify content, etc.

In this article, we'll see how to use a helper to display a special message for the Experience Editor, this could be an informative or warning one.

Helper code

In this code we will see two methods to display a message in the Experience Editor, validating that it is in that mode according to the context, and with special styles.

public static class ExperienceEditorMessage
{
    public static HtmlString Info(string message)
    {
        return !Context.PageMode.IsExperienceEditorEditing 
            ? new HtmlString(string.Empty) 
            : new HtmlString($"<div style=\"background: #AADBEE; margin: 10px 0px; padding: 10px 8px; border-radius: 8px; font-size: 12px;\"><b style=\"font-weight: bold;\">Info</b>: {message}</div>");
    }

    public static HtmlString Warning(string message)
    {
        return !Context.PageMode.IsExperienceEditorEditing 
            ? new HtmlString(string.Empty) 
            : new HtmlString($"<div style=\"background: #f8f8a0; margin: 10px 0px; padding: 10px 8px; border-radius: 8px; font-size: 12px;\"><b style=\"font-weight: bold;\">Warning</b>: {message}</div>");
    }
}
Enter fullscreen mode Exit fullscreen mode

Example from a view

From the view of a component, this way we can display the expected message.

@ExperienceEditorMessage.Info("This is an Experience Editor message for general information.")

@ExperienceEditorMessage.Warning("This is an Experience Editor warning message.")
Enter fullscreen mode Exit fullscreen mode

This is the result in the Experience Editor:

Experience Editor examples

Thanks for reading!

And that's it! With this proposed solution we can show a special message in the Experience Editor for Content Authors. If you have any questions or ideas in mind, it'll be a pleasure to be able to be in communication with you, and together exchange knowledge with each other.

X / LinkedIn - esdanielgomez.com

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay