2

Does anyone know of a concept like Sitecore.Context.PageMode inside the Sitecore 9 Forms editor?

I would like to use this in the cshtml files (Views/FormBuilder/FieldTemplates/*.cshtml) to show some additional information for editors, but it may only be vissible in the editor and not when the form is rendered on the actual page.

For info: Sitecore.Context.PageMode.IsNormal == true in the forms editor.

1 Answer 1

6

No, there is nothing out of the box, but a sc_formmode url parameter is present whenever you are in Form Builder mode. The value is new or edit depending on the context, but just checking for the presence of the parameter is sufficient.

You can create an extension method to make this more reusable:

using Sitecore.Mvc.Helpers;

namespace MyCustom.Forms.Feature.ExperienceForms.Extensions
{
    public static class HtmlHelperExtensions
    {
        public static bool IsExperienceForms(this SitecoreHelper helper)
        {
            return Sitecore.Context.Request.QueryString["sc_formmode"] != null;
        }    
    }
}

In your views you can then detect the mode and render your markup as required:

@if (Html.Sitecore().IsExperienceForms())
{
    @* render Forms Builder mode *@
}
else
{
    @* render normal view *@
}

You can read more in this blog post by Joao Neto.

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.