Build a Sitecore Custom RTE and Serialize to File System and sync back to Sitecore using Unicorn

This blog article covers a bare minimal project to create a Unicorn setup, creates a customized Rich Text Editor then perform Unicorn serialize, sync to see the changes work fine!

1. Create an ASP.NET Web Application (.NET Framework) project.

2. Install Unicorn nuget package:

3. Since my target Sitecore version is 10.2, I disabled Unicorn.DataProvider.config.

4. Then, I set my root web.config in my Visual Studio solution as follows:

Build Action: None
Copy to Output Directory: Do not copy



5. Then, setup a Visual Studio publish folder profile to the website root.

6. Ensure users have full control over the webroot folder:


7. Now, publish from visual studio and the publish must be successful:


8. Now, when you access unicorn.aspx, you should see this page:


9. Next, will add just the minimal configurations to serialize core db items, specifically rte related menu. As per that approach, source folder location added in the Visual Studio solution: App_Config\Include\zzzz\SourceFolder.config:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
    <sitecore>
      <sc.variable name="sourceFolder" value="C:\Users\conta\source\repos\WebApplication10\WebApplication10" />
    </sitecore>
  </configuration>

10. Serialization must happen for only the core db items, specifically, this path in Sitecore: 
/sitecore/system/Settings/Html Editor Profiles/Project/Sitecore/Rich Text Custom

So, specify the same in Visual Studio solution under \App_Config\Include\Project\Website\Sitecore.Project.Website.config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore role:require="Standalone or ContentManagement">
    <unicorn>
      <configurations>
        <configuration name="Project.Sitecore.Website" description="Website content" dependencies="Foundation.*,Feature.*">
          <targetDataStore physicalRootPath="$(sourceFolder)\$(layer)\$(module)\serialization" useDataCache="false" singleInstance="true"/>
          <predicate>            
           <include name="Settings" database="core" path="/sitecore/system/settings/Html Editor Profiles/project/Sitecore" />
          </predicate>        
        </configuration>
      </configurations>
    </unicorn>
  </sitecore>
</configuration>

11. This is how my VS sln looks now:


12. When you access the unicorn.aspx, this is how it looks:


13. Next, I setup a custom RTE in Sitecore Core DB as follows under /sitecore/system/settings/Html Editor Profiles/project/Sitecore:


If you are a Helix proponent, you would prefer to put this one in Foundation or Feature layer but since this is an example, just keeping it minimal!

14. Time to serialize to file system from the Unicorn page:


15. Should be able to see a new folder as follows in the file system based on the source folder path specified in sourcefolder.config above:

C:\Users\conta\source\repos\WebApplication10\WebApplication10\Project\Sitecore\serialization




16. Now, the idea of the new RTE is to keep all options except the background color fill:
\

17. Since the yml files are already serialized to the file system, I delete the backcolor.yml file from the file system in the following location:
Project\Sitecore\serialization\Settings\Sitecore\Rich Text Custom\Toolbar 2


18. Now, sync the files to Sitecore using Unicorn page:

https://sc102ltsc.dev.local/unicorn.aspx?verb=sync

Backcolor fill not present in Core DB now:



19. Next, switch to Master DB and create a template that is same as Sample Item but rename it as New Item and the RTE here will point to the newly created core item:




20. Now, I alter my serialization settings to include this new template, then remember to do a Visual Studio Publish of this config file!



Note that the Master db in the above line must be master and not Master since id is case-sensitive and hence will throw an error.

21. Since I just have one set of files, I cleanup the serialization folder in the file system and perform Initial serialization from the Unicorn page:


22. The end-result is satisfactory:


23. File System:




24. Add the new template to the Sitecore Content tree to cross-check the end-result:


Background color fill button is not visible in the custom RTE!

Comments