Preview Publishing Target – Enable Normal View For Non-Sitecore Users

Enabling normal view to non Sitecore users to review changes before publishing the actual changes to production site – preview publishing target

Sometimes, we got requirements from client that some of their executives will also required to review the site changes before publishing it to live site, and upon that those executives will be non Sitecore users. In this case we need to enable normal view mode for non Sitecore users so that they can review changes before reaching to final state of workflow to publish to public site.

Sitecore has introduced a feature called Preview Publishing Target which allows us to publish the items to that specific target ignoring in which state of workflow an item is.

Let’s create a Preview Publishing Target and enable normal view for the non Sitecore reviewers step by step:

  • Create a copy database of web. We have named it here preview_web.
  • Add connectionstring in App_Config/Connectionstrings.config with above specified name preview_web.
  • Add database node in App_Config/Sitecore.Config <databases> pointing to above database preview_web.
  • Add new publishing target to /sitecore/system/Publishing targets/
  • 1
  • Check Preview publishing target check-box as shown in above image
  • Publish this item to both the target web and preview_web.
  • Go to workflow used in your site -> select state -> select the preview publishing targets from the list as shown below:
  • 2
  • Do the same steps for all the necessary workflow states.
  • Publish the workflow with subitems.
  • Now accessing item which is using above workflow, you can see the note as shown below:
  • 3
  • Now add a new site in site definitions in ~/App_Config/Sitecore.Config
  • <site name="previewsite" hostName="scpreview" enableAnalytics="true" enableTracking="true" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/homepage" database="preview_web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="50MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="25MB" filteredItemsCacheSize="10MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" cacheRenderingParameters="true" renderingParametersCacheSize="10MB" />
    
  • Add bindings and host entry for above demo host
  • Now, make changes, publish changes to both web and preview_web instances before submitting or approving in final workflow state, changes will be visible in the above preview site. While live site will remain unchanged.

Note:

Hope this will help you in implementing similar scenario.

Using Display Name and Generating links for multilingual sites – Sitecore

About Display Name:

As many of us already aware, Display Name is used

In case of multilingual sites, where we required to generate links for pages specific to the language it is serving. For ex: there is a page in website named about-us and website is available in two languages English, and German. Now URL should be formed according to language as shown below:

This can be achieved by the feature referred as Display Name in Sitecore.

How to Assign Display Name

  • Create an item in Sitecore with the preferred name, in our example it is about-us.
  • For English language version display name will be same as item name so we will skip this part for English language.
  • For German language, Select the German language version of an item, click on Home (tab) -> Rename (chunk) -> Display Name command from the ribbon bar in content editor (You can also assign Display Name from Experience Editor).
  • A popup will appear expecting a text, enter the display name specific to the language which will then be used to form language specific URL. In our example equivalent to contact-us will be kontaktiere-uns, so enter this in textbox and save.
  • That’s it from the configuration part. You will see entered display name in content tree now instead of item name.

Generating Links While Using Display Name Feature

To generate URL specific to language using Display Name, You need to add useDisplayName=”true” into linkmanager in the sitecore.config. See below:


<linkManager defaultProvider="sitecore">
    <providers>
      <clear/>
      <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="always" languageLocation="querystring" lowercaseUrls="true" shortenUrls="true" useDisplayName="true"/>
    </providers>
</linkManager>

After enabling Display Name in link manager, you can now generate link using link manager as follow:

Consider context language as English, and we need to generate link for German language version of item using display name. We can do it simply using link manager in view as:


@{

Sitecore.Links.UrlOptions options = new Sitecore.Links.UrlOptions();
options.Language = Sitecore.Data.Managers.LanguageManager.GetLanguage("de-DE");
options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Always;
options.LanguageLocation = Sitecore.Links.LanguageLocation.QueryString;
options.UseDisplayName = true;

string URL = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item, options);

}

Will this generate the link we desire for German (de-DE) language? No.

The link generated using the above code will look something like http://[hostname]/about-us?sc_lang=de-DE

Why we are showing about-us in the URL instead of the kontaktiere-uns even though we have supplied language de-DE in UrlOptions.

After drilling down to Linkmanager code, come to know that language passed into UrlOptions not getting used while getting Display Name, It is getting Display Name of the item provided as first parameter of GetItemUrl()

In our case we are passing context item, and context language is English. As we do not have provided any Display Name for this item in English language, it will use Item Name itself to generate the URL.

So, we need to get the item in specific language before passing to GetItemUrl() function to form valid URL specific to language with help of Display Name. See below:


@{

string URL = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item, options);

}

In place of above line use below code:


@{

string URL = @Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Database.GetItem(Sitecore.Context.Item.ID, Sitecore.Data.Managers.LanguageManager.GetLanguage("de-DE")), options);

}

So, above code will first get German version of the about-us item, and thus will form a valid URL using Display Name provided for German language.