November Happy Hour will be moved to Thursday December 5th.

How best to merge blocks?

Vote:
 

Hey friends. We have several different block types with mostly the same properties. Many of these blocks have the same content in them but render differently. Our content team wants to consolidate these blocks into one single block, and we then use template descriptors to handle the different renderings.

There is a feature to convert pages, but this still doesn’t do blocks unfortunately. I know Gulla has made his own version/copy for blocks. But that package is for CMS 11. We could follow his example and copy the stored procedures and make them work for blocks. This looks to me as the most viable option what I’ve seen so far.

As for the duplicate content, what would be the best way to replace one block instance with another? The IContentRepository has the method GetReferencesToContent which seems like a good start, but I don’t see any save-equivalence of that method, so we need to loop though each property of each reference content and change the content links? I hope there is a simpler way of doing this that we missed.

#291623
Nov 14, 2022 8:46
Vote:
 

Any suggestions would be very welcome!

#292068
Nov 22, 2022 8:09
Vote:
 

Personally, until an admin tool to convert blocks is made by Optimizely, I would just write a scheduled job to do the conversion. No add-ons, plugins, or SQL scripts. Just use the various provided services to do what I need to do:

  • Use IContentModelUsage to get all the content references of a specific content type ("source" blocks)
    • Use the method ListContentOfContentType, then select distinct content references without the version number.
  • Use IContentRepository to get the content item of the "source" block.
  • Use IContentRepository to create a default instance of your "target" block.
    • You can use IContentAssetHelper to get an asset folder content link for the default instance's parent content link.
  • Copy property data from the "target" block to the "source" block.
  • Use IContentRepository to save the "target" block.
  • Optionally, use IContentRepository to delete the "source" block. Maybe do this after you know everything works. :)
#292113
Nov 23, 2022 3:59
Vote:
 

Tomas Gulla made a package to do just this, but it's only out for CMS 11, but I'm sure it could help with guidance.

GitHub: https://github.com/tomahg/Gulla.Episerver.BlockConverter

Original Blog: https://blog.novacare.no/convert-episerver-blocks/

#292331
Nov 28, 2022 14:08
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.