title: Render child items with their own layout in a carousel control
body: <p>Here is what I am trying to do:</p>
  
  <p>I have a content item "Carousel Presenter". Essentially this will present its child items within the carousel. I want the flexibility to have any number of child items. I also want the flexibility to be able to specify the presentation of each child item - they may be the same or different. I am using Sitecore 6.5.</p>
  
  <p>The carousel is jcarousel. I need to generate markup generally like this (from item "Carousel Presenter"):</p>
  
  <pre><code>&lt;div class="jcarousel"&gt;
      &lt;ul&gt;
          &lt;li&gt; ... MARKUP FROM ITEM 1 ... &lt;/li&gt;
          &lt;li&gt; ... MARKUP FROM ITEM 2 ... &lt;/li&gt;
          ... and so on
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is what I have tried:</p>
  
  <ul>
  <li><p>Created sublayout "carousel presenter.ascx", markup:</p>
  
  
      <ul>
          
      </ul>
  </li>
  </ul>
  
  <p>Codebehind:</p>
  
  <pre><code>  protected void Page_Load(object sender, EventArgs e)
      {
          // Get all children and render them inside the &lt;ul&gt;
          var kids = Sitecore.Context.Item.GetChildren();
          foreach (Item snippet in kids)
          {
              // RENDER THE ITEMS HERE INTO THE PLACEHOLDER...
              // Get the first rendering from item's presentation definition
              RenderingReference rendering = snippet.Visualization.GetRenderings(Sitecore.Context.Device, false).FirstOrDefault();
              // We assume that its a Sublayout, but you can also check for xslt and create an XslFile() object
              Sublayout sublayout = new Sublayout();
              sublayout.DataSource = snippet.Paths.FullPath; // creates a reference to the snippet item, so you can pull data from that later on
              sublayout.Path = rendering.RenderingItem.InnerItem["Path"];
              sublayout.Cacheable = rendering.RenderingItem.Caching.Cacheable;
              // Copy cache settings
              if (rendering.RenderingItem.Caching.Cacheable)
              {
                  sublayout.VaryByData = rendering.RenderingItem.Caching.VaryByData;
                  sublayout.VaryByDevice = rendering.RenderingItem.Caching.VaryByDevice;
                  sublayout.VaryByLogin = rendering.RenderingItem.Caching.VaryByLogin;
                  sublayout.VaryByParm = rendering.RenderingItem.Caching.VaryByParm;
                  sublayout.VaryByQueryString = rendering.RenderingItem.Caching.VaryByQueryString;
                  sublayout.VaryByUser = rendering.RenderingItem.Caching.VaryByUser;
              }
              // Now render the sublayout to the placeholder
              carouselItemsPh.Controls.Add(sublayout);
          }
      }
  </code></pre>
  
  <p>Note that I stole most of this code from here: <a href="https://stackoverflow.com/questions/9666805/temporarily-change-a-sitecore-items-layout">Temporarily change a Sitecore item&#39;s layout</a></p>
  
  <ul>
  <li>Created child items in content tree, beneath content item "Carousel Presenter" which are "Carousel Items", with a sublayout control assigned to each (via standard values in configuration/layout).</li>
  </ul>
  
  <p>Everything is published.</p>
  
  <p>When I hit my test page markup is generated for each of the child items ("Carousel Items"), and the carousel works, but it looks like the Datasource is not being assigned properly - the datasource/context of all child items is the parent item, despite setting the Datasource explicitly when I create the child controls. How do I fix this?</p>
  
  <p>Is there a better approach to what I am trying to achieve in Sitecore 6.5?</p>
  
  <p>Thanks</p>