Site structure
Version 5.x > Site structure > Sharing Content View modes: 
User avatar
Member
Member
gcormier@lighthousesolutions.com - 5/25/2011 2:22:19 PM
   
Sharing Content
Alright there has to be a way to do this:

On the home page of my site I've got some content in editable region A.

On another page, I've got an editable region B where I want to dynamically share the content from home page editable region A.

So, when I update content on home page editable region A... It dynamically shows on the other page.

How?

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 5/31/2011 3:31:51 AM
   
RE:Sharing Content
Hello,

This scenario is not natively supported; however, you can still develop it by yourself. I believe that the easiest way is to have just one Editable region on one document, where you'll maintain the content and all the changes will be automatically mirrored to another document.

For this purpose, I would recommend you to create a new custom web part which will handle the mirroring work. In short, you just set the PageInfo object which contains appropriate Editable region web part and then you'll add the Editable region content to some literal control available in this web part.

When it comes to coding, the whole web part code-behind can look as follows (the custom part is mainly in the SetupControl method)(assuming there is the ltlText literal):

using CMS.PortalControls;
using CMS.GlobalHelper;
using CMS.CMSHelper;
using CMS.ExtendedControls;

using CMS.SiteProvider;
using CMS.DataEngine;

public partial class CMSWebParts_Text_EditableRegionMirrorCustom: CMSAbstractWebPart
{
/// <summary>
/// Gets or sets the text to be displayed
/// </summary>
public string SourceEditableRegionID
{
get
{
return HTMLHelper.ResolveUrls(ValidationHelper.GetString(this.GetValue("SourceEditableRegionID"), ""), null);
}
set
{
this.SetValue("SourceEditableRegionID", value);
}
}
/// <summary>
/// Gets or sets the source document alias path
/// </summary>
public string SourceDocument
{
get
{
return ValidationHelper.GetString(this.GetValue("SourceDocument"), "");
}
set
{
this.SetValue("SourceDocument", value);
}
}

/// <summary>
/// Content loaded event handler
/// </summary>
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}


/// <summary>
/// Initializes the control properties
/// </summary>
protected void SetupControl()
{
if (this.StopProcessing)
{
// Do not process
}
else
{
// Get the Page info
CMS.PortalEngine.PageInfo pi = CMS.PortalEngine.PageInfoProvider.GetPageInfo(CMS.CMSHelper.CMSContext.CurrentSiteName, this.SourceDocument, CMS.CMSHelper.CMSContext.CurrentDocument.DocumentCulture, "", true, CMS.DataEngine.ConnectionHelper.GetConnection());

if (pi != null)
{
// Set the selected editable region value to the literal
this.ltlText.Text = pi.EditableWebParts[this.SourceEditableRegionID.ToLower()].ToString();
}
}
}

/// <summary>
/// Reloads the control data
/// </summary>
public override void ReloadData()
{
base.ReloadData();

SetupControl();
}
}


Please note, in the example above, I used two custom web part properties for the Editable region ID and Document alias path. Those can be defined on the Site Manager -> Development -> Web parts -> Your_Web_Part -> Properties tab.
In fact, the SourceEditableRegionID field is just a textbox and SourceDocument field is of type Single path selector.

At any rate, please consider that code as a simple example and adjust it as per your needs.

Best regards
Ondrej Vasil