Surendra Sharma

Surendra Sharma

Search This Blog

Thursday, August 17, 2017

Change template of existing Sitecore items without losing data

Change is the law of nature. You can't expect change in already running Sitecore website. Some changes are minor while some changes modified the original logic itself.

Here is a real life scenario:

You have multiple website running on same Sitecore instance. You have one template let’s say "Practice" and you created multiple items(let’s say 100) from this "Practice" templates in multiple websites. Now you have to add some additional fields for only one of the website for Practice related items and require new presentation details.

Here half of the requirement of additional fields can be handlled by adding fields to existing template. But what about adding new presentation details to all items of single website.

One approach is that create new template and apply it to new items. But problem is that we will lost or need to change existing data in new items.

Is there any better approach where we can use same items, get filled data, new fields and new presentation details for one website only?

I use below approach for this

1. Create new template "Practice New" as a copy of existing template "Practice"
2. Applied new presentation details to standard values of template "Practice New".
3. Select Practice item inherited from existing “Practice” template in content tree
4. Change Template
            Select Configure -> Change -> Select "Practice New” -> Next and change existing item to 
new template as

Change Template
Change Template
5. Reset presentation details
            Click on Presentation -> Reset for applying new presentation to the item as

Reset Layout
Reset Layout

6. This is important step as we want to remove all the presentation details from item and want to set default presentation details of new template. So select Reset presentation for every language and its version including both final and shared layouts as

Reset final and shared layout
Reset final and shared layout

7. Apply any data source to items presentation component
8. Publish
9. Test

In short - apply new template, reset presentation details, change data sources and publish item.

I hope you like this Sitecore trick. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this trick if it’s useful for you.

Wednesday, August 16, 2017

Sitecore bug: Clone item with language fallback

I have checked this in Sitecore 8.1 and 8.2. Sitecore support team accepted it as a bug.

Here is the bug details:

If you have any item with language fallback and now if you create a clone of this item then you will not get language fallback on clone item. Instead of that you will get language version on clone item.

Here are steps to reproduce it
  • Let’s suppose you have 3 languages – English, French and German.
  • Both French and German languages are fallback to English.
  • Create an item where French is fallback to English and German have 2 versions as

Original Item with language fallback
Original Item with language fallback
  • Now create a clone of this item as
Clone item with language versions
  • As you can notice from image, French is not fallback to English on cloned item, instead an actual French version of the item is created.
  • Also we have 2 versions of German in original item but in clone item, only a single German version is created. This single version of cloned German is pointing to latest version of Original German item i.e. version 2.
  • You can verify this from “Create from” label and “Advanced/Source” field as highlighted in above image. As per Sitecore this “Single German Version” is expected behavior but French fallback Vs its version is a bug.
Sitecore had provided a patch for this bug for one of our project in Sitecore 8.1. But when I tested it in Sitecore 8.2, I am able to reproduce this.

Those who have multi lingual site, clone and fallback items should check this in their environment.

Please leave your comments or share this bug details if you care for any related Sitecore project.

Sunday, August 13, 2017

How to render Brightcove video programmatically using sitecore item

Brightcove and Sitecore using CSharp
Brightcove and Sitecore using CSharp

It’s very easy to render Brightcove video through HTML as

<iframe src="//" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>

But do you know how to render it through programmatically?

Let’s suppose you are getting video item id and player id through Sitecore in your MVC view as

var playerHtml = string.Empty;
    playerHtml = HelperClass.Instance().GetVideoPlayerMarkup(Model.VideoItemGuidId, Model.PlayerGuidId, 170, 300);
<script language="JavaScript" type="text/javascript" src=""></script>
<script type="text/javascript">

This view calling GetVideoPlayerMarkup() method which accept 4 parameters – video item id, player item id, video player’s height and width.

You need to include below namespace for using this method

using Sitecore.MediaFramework.Pipelines.MediaGenerateMarkup;
using Sitecore.MediaFramework.Players;

Here is a C# code for this method as

public virtual string GetVideoPlayerMarkup(ID videoItemId, ID playerItemId, int height, int width)
    var playerHtml = string.Empty;
    PlayerProperties playerProperties = new PlayerProperties()
        ItemId = videoItemId,
        PlayerId = playerItemId,
        Height = height,
        Width = width
    MediaGenerateMarkupArgs args = new MediaGenerateMarkupArgs()
        MarkupType = MarkupType.Html,
        Properties = playerProperties
    if (!args.Aborted)
        playerHtml = args.Result.Html;
    return playerHtml;

That’s it. Now when you render this view you will get the Brightcove video on the browser.

I hope you like this Sitecore-Brightcove integration through code. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this code if it’s useful for you.