Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:03:19+00:00 2026-06-15T12:03:19+00:00

I have a custom sitecore button which changes the template of the current item,

  • 0

I have a custom sitecore button which changes the template of the current item, simple enough.

However as part of this I’m trying to also migrate the renderings of the old layout to a new layout if it’s of a certain sublayout type by ItemId. However the ItemId that is returned is always null, the only value I get back from the RenderingDefinition is the UniqueId.

What am I doing wrong?

I have used this blog post as a guide.

The Code

public class ConvertToNewTemplateCommand : Command
{
protected void Run(ClientPipelineArgs args)
{
    if (!SheerResponse.CheckModified())
        return;

    Item item = Context.ContentDatabase.Items[args.Parameters["id"]];
    if (args.IsPostBack)
    {
        if (args.Result == "yes")
        {
            //Get current layout details
            var originalLayoutXml = item[FieldIDs.LayoutField];

            //Get new template
            TemplateItem hubTemplate = Context.ContentDatabase.GetTemplate("some guid...");
            //Change template  
            item.ChangeTemplate(hubTemplate);
            //Reset laytout
            ResetLayout(item);
            //Get reset layout
            var newLayoutXml = item[FieldIDs.LayoutField];

            //Add all the module containers to the new layout in the central column
            MoveModuleContainers(item, originalLayoutXml, newLayoutXml);
        }
    }
}

private void MoveModuleContainers(Item item, string oldXml, string newXml)
{
    var oldLayout = LayoutDefinition.Parse(oldXml);
    var newLayout = LayoutDefinition.Parse(newXml);

    bool updated = false;

    var oldRenderings = (oldLayout.Devices[0] as DeviceDefinition).Renderings;
    var newRenderings = (newLayout.Devices[0] as DeviceDefinition).Renderings;

    foreach (RenderingDefinition rendering in oldRenderings)
    {
        // Here is where the rendering.ItemID is always null
        if (rendering != null && !String.IsNullOrEmpty(rendering.ItemID) && new Guid(rendering.ItemID) == new Guid("matching guid..."))
        {
            rendering.Placeholder = "middlecolumn";
            newRenderings.Add(rendering);
            updated = true;
        }
    }

    if (updated)
    {
                   // Save item...
            }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:03:21+00:00Added an answer on June 15, 2026 at 12:03 pm

    I got onto Sitecore support in the end which informed me that I should use:

    Sitecore.Data.Fields.LayoutField.GetFieldValue(item.Fields[Sitecore.FieldIDs.LayoutField])
    

    instead of:

    item[FieldIDs.LayoutField]
    

    to get the items layoutField correctly. This results in the rendering values being parsed correctly and as they say the rest is history.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom javascript code for tabs which works fine, but Im trying to
I have custom radio buttons which I've borrowed from this website: http://www.inserthtml.com/2012/06/custom-form-radio-checkbox/ Unfortunately, I'm
In Sitecore I have created a custom field (via this recipe: http://sdn.sitecore.net/Articles/API/Creating%20a%20Composite%20Custom%20Field/Adding%20a%20Custom%20Field%20to%20Sitecore%20Client.aspx ) The
I have custom Rythm template tag (sayHi.html) which I want to call from parent
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom validation rule: public function customRule($check) { } Inside this rule I
In my Sitecore 6.1.0 installation I have hooked onto the item:added event by implementing
I have custom radar tiles that I am trying to overlay over Google Maps
I have custom page and id of list item. How can i show sharepoint
I have a Sitecore content structure where any single item can have a number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.