2
votes

I have a template called 'Footer' which contains a Rich-Text Field.

Footer Template with a Rich-Text Field

Using the Footer Template I have created an Item called 'FooterComponent' and filled in the Rich-Text Field.

FooterComponent item with Rich-Text Field filled

I have a sublayout called 'Footer-Sublayout' and Mapped the Visual studio sublayout with this.

Using Footer-Sublayout C# code I have to fetch the Rich-Text field from the 'FooterComponent' and display it in my Home Page.

2

2 Answers

0
votes

You need to add the footer sublayout to the presentation detail of the homepage and bind it to the placeholder that corresponds to the one in the code.

In the code behind of the footer sublayout, you will then need to fetch the value from the rich text field of the item. So, first get the footer item either by path or template ID. Second, read the value of the rich text field.

Thanks

0
votes

Give your Footer-Sublayout a datasource. In your code you can request the datasource of the rendering/sublayout (the exact how can differ, depending on the sitecore version, frameworks used (glass, ..) but can be easily found).

By using a datasource (and not hardcoding the item in your code) you give your editors the ability to change the item without changing code - or use the personalization/testing features of Sitecore.

e.g. (in v7 without frameworks):

public Item GetDataSource(Control parent)
{
  var sublayout = parent as Sublayout;
  return sublayout != null ? Context.Database.GetItem(sublayout.DataSource) : null;
}

Use the parent of your control in this function to retrieve the datasource item. Once you have the item, you can attach it to a FieldRenderer or fetch the fields in code.