Skip to main content

Sitecore

From Shared to Final Layout: Sitecore Rendering Made Easy with PowerShell

Microsoftteams Image

In the course of one of our recent projects, we encountered a noteworthy challenge that arose from a customized rich text rendering solution. To enhance our Sitecore SXA capabilities, we developed a customized rendering by cloning an existing Sitecore SXA out-of-the-box component. The entire process was meticulously documented for the benefit of content authors, providing guidance for both the Content Editor and Experience Editor workflows.

However, a significant hiccup emerged when content authors, initially working in the Content Editor, inadvertently added the required rendering to the Shared Layout. This realization struck after the fact, leading to the addition of this rendering across a staggering 700+ pages.

Upon learning about this predicament, our development team embarked on a quest to find a solution. After exploring various approaches, we zeroed in on the PowerShell script as the optimal choice. In this blog post, I will delve into the intricacies of the problem statement, the challenges faced by content authors, and, most importantly, unveil the PowerShell script we crafted to seamlessly move renderings from the Shared Layout to the Final Layout. What sets our script apart is its user-friendly design, allowing content authors to submit their parameters for processing, ensuring a smooth transition for their requests.

How to Move a Sitecore Rendering from Shared Layout to Final Layout

Using these selections, we’ve orchestrated the execution in the PowerShell script. The script is equipped with multiple features:

  1. Authors can remove the rendering from the Shared Layout.
  2. Authors can move the rendering from the Shared Layout to the Final Layout with or without the Data Source.
  3. Authors can selectively add the rendering to the Final Layout with or without Data Source without impacting the Shared Layout.

You can download or copy-paste the PowerShell script from this link. If you dive into the script, you’ll find that we’ve structured it to collect essential parameters from content authors. These include the root item, template name, rendering ID (to be moved from Shared Layout), placeholder key (indicating the placeholder from which to remove the rendering in Shared Layout and add it to the Final Layout), rendering path (specifying the rendering to be added in the Final Layout), language (language version), and a few confirmations for removing the rendering from Shared Layout, adding it to Final Layout, and utilizing the same Data Source in Final Layout if it’s available in the Shared Layout.

To execute this script, content authors need to follow the steps outlined below.

Step 1: Open Sitecore PowerShell ISE.
Powershell Ise
Step 2: Either open the downloaded PowerShell script or copy-paste the script content into ISE.
Step 3: Execute the script (which requires administrator rights).
Admin Acess Require
Step 4: Once you hit the execute button, a dialog box will open, prompting you to specify the Root item.
Root Item
Step 5: Next, it will ask for the template name of the content items.
Template Name
Step 6: After that, it will request the rendering ID.
Rendering Id
Step 7: Enter the placeholder key in the dialog box.
Placeholder Key
Step 8: Input the path of the rendering that needs to be added to the Final Layout.
Rendering Path
Step 9: Enter the language version.
Language Version
Step 10: Press OK if you want to remove the given rendering from the Shared Layout.
Shared Layout
Step 11: Press OK if you want to add the given rendering to the Final Layout.
Final Layout
Step 12: Press OK if you want to use the same data source in the Final Layout.
Datasource

As we explored the nuances of the problem statement and the script’s capabilities, we witnessed the transformative impact it had on our development process. The script’s user-friendly design, coupled with its ability to handle diverse scenarios, proved to be a valuable asset for our team. It not only simplified the transition process from Shared to Final Layout but also empowered content authors with a newfound agility in rendering adjustments. As we conclude this exploration into Sitecore rendering with PowerShell scripting, we encourage fellow developers and architects to embrace the power of automation. The script shared here is not just a technical solution; it’s a testament to the adaptability and innovation that can thrive within development teams.

I plan to share a few more PowerShell scripts in my next couple of blogs that solved our problems in the project, so please stay tuned. Your continued engagement and feedback are invaluable as we navigate the exciting landscape of Sitecore development.

Happy Scripting!

Thoughts on “From Shared to Final Layout: Sitecore Rendering Made Easy with PowerShell”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sumit Salpekar

Sumit Salpekar, an engineering graduate working as Lead Technical Consultant, is a Sitecore certified professional with 10 years of web development experience and 7 years of experience on Sitecore platform. He likes to explore challenging and trending topics in Sitecore. He worked on numerous Sitecore projects on multiple versions and deliver it successfully.

More from this Author

Categories
Follow Us