Search code examples
sitecoredatatemplatesublayout

Sitecore: Add a New Data Template to my Sublayout


I sublayout is about Events. If I put it inside a page which contains an Event, it will display informations pertaining to it.

I want to add a Data Template to my Sublayout that will allow editors to specify one particular Event from which to draw these informations.


How do I go about creating a Data Template that allows an editor to choose a specific Event from a list? How do I add this to a given Sublayout?


Solution

  • When building componentized architectures as you are doing, you will want to implement the datasource property for a sublayout to make your sublayout a datasource-driven sublayout.

    This article by John West should help on how to set a datasource: http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/How-to-Apply-Data-Sources-to-Sitecore-ASPNET-Presentation-Components.aspx

    The basics are:

    1. Create a template for your Event to contain the data
    2. On your sublayout item (/sitecore/Layouts/...) set the datasource template property to match to your new Event template.
    3. Update your code to pull from the datasource item on the sublayout, not the Sitecore.Context.Item

    The following post by Mark Ursino is helpful in seeing the code side as well: http://firebreaksice.com/using-the-datasource-field-with-sitecore-sublayouts/