1

I'm trying to make Sitecore Forms easier for my content editors to use. They use the Content Editor and never touch layouts, controls, or renderings.

I've made an item template with a single droptree called "Form". It's data source is "/sitecore/Forms" This allows my content editors to select a form without going into presentation > details > edit > controls > Mvc Form > edit > Data Source > Browse, and missing a step and calling me when they break the page.

To get this to work, I need to set the Data Source of that control to a query that looks at the current item's "Form" field's value and uses the item linked as the Data Source for the control. What query do I need here?

If a query is not possible could I place a control into the layout before the "Mvc Form" control that reads the field's value and sets the datasource on the "Mcv Form" control?

1
  • Are you here looking for the query to select the specific datasource, so that the content author can easily chose the datasource? Dec 8, 2023 at 7:01

1 Answer 1

3

I have an idea for you!

You can create an intermediate View Rendering that renders the Form programmatically with a custom datasource. This new rendering can be added or removed to any page. The datasource of this new rendering is the current item's Form field or another one (it gives you the flexibility to change the datasource anytime).

Your view should contain something like that:

@Html.Sitecore().Rendering("{6B5B0FE6-5C85-4487-BA7E-F8C2ECC186A8}", new { DataSource = "YOU_ITEM.Fields['YOUR_FIELD'].Id" }).

Where:

  • {6B5B0FE6-5C85-4487-BA7E-F8C2ECC186A8} is the id of the OOTB Form /sitecore/layout/Renderings/System/Forms/Mvc Form
  • You're free to implement the custom logic for the datasource in the Razor View

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.