Recently, for one of our projects, we found that a large number of the client’s renderings were using rendering parameters unnecessarily. In order to allow for personalisation and a better Experience Editor experience, we recommended to the client that they change these renderings to use datasources instead.
The process (which may vary slightly for your instance) went something like this:
For each rendering to be converted:-
- Move the related rendering parameters template from its current folder (which in this case was a folder dedicated to rendering parameters) to a more appropriate folder for data item templates.
- Make sure that all sub-items are serialised when the template has been moved – I encountered what seems to be a bug with Unicorn, where it doesn’t serialise them. If you get this, you might need to reserialise, or save each sub-item manually.
- If the template currently has a name specific to rendering parameters, rename it to something more appropriate.
- If required, make sure that the _Standard Values are set.
- Where the rest of your site data lives, create a new folder which will be used to store items of the template in question. Set the insert options to add this template.
- Change the rendering’s datasource location to be the newly created folder.
- Change the rendering to have no rendering parameters template, and instead use a datasource template of the recently moved template.
- Remove the “Standard Rendering Parameters” template from the base templates of the new datasource template.
- Add a new item to Core DB with the path something like: /content/Applications/WebEdit/Edit Frame Buttons/Signup Form Button/Signup Form
- Set Fields for this new item to be a pipe-delimited list of fields that the content editors will need to edit (generally all of them).
- In the Visual Studio solution, move the rendering parameters model into the folder where the data items models live, and rename the file and class name if required.
- Change the namespace to match the new location.
- Inside the controller method (assuming the rendering is a Controller rendering), remove all code that uses the rendering parameters, and instead, set the datasource to be the RenderingContext.Current.Rendering.DataSource.
- Change the view using this rendering:
- Add a check for if (Model != null), and display a message if in experience editor mode.
- Add “using (BeginEditFrame…” and use the path of the folder for the webedit button you added earlier.
- Added a check for Sitecore.Foundation.SitecoreExtensions.Extensions.ItemExtensions.IsDerived using a configuration item for the template ID. Display a message if wrong template and skip the rest of the view.
- Changed all references to items in the Model be use @Editable(x => x.)