based on a single page view I am looking to have my content structure dynamically build the page.
So as an example: with a child item of GALLERY template, this would itself have sub-items using the GALLERY ITEM template which defines each of the images to be shown in a carousel; so an Editor can simply add multiple items and the carousel will scale accordingly rather than having fixed fields (banner, banner 2 etc)
Currently I am having an issue in understanding how my sublayout which defines the galleries HTML can automatically be included in this main page if that template is present.
Rather than an Editor having to manually add the Sublayout and define a datasouce to the gallery node I'd want the main page to iterate down the tree and observe there is a template for GALLERY therefore knowing it needs to use the sublayout and add it to the main page placeholder
On this principle the page will self build depending on what items an Editor adds to the page.
Any advice or sample code (using webforms) is appreciated; currently I am having to manually add sublayouts which seems to not be intuitive for Content Editors to assemble pages.
Thanks
If you are properly using and configuring the Page/Experience Editor, adding the sublayouts and data sources is a very intuitive process, and allows you to take full advantage of all the features and capabilities of Sitecore, in particular personalization and A/B testing. This is the recommended practice that you should follow.
That said, if you have extenuating circumstances that really prevent you from doing this, there is an older technique called "Presentation Inversion of Control" which pulls renderings from items associated via the content tree. It was useful prior to the "unified page editor" and datasource wizards which appeared in Sitecore 6.4. There are various approaches to this, but the simplest is a sublayout/web control that you place on the page.
The following code hasn't been tested by be on Sitecore 7:
public partial class Gallery: System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
PageItem page = Sitecore.Context.Item;
//custom item contains logic for finding items to include
foreach (Item galleryItem in page.GalleryItems)
{
string strDataSource = galleryItem.ID.ToString();
RenderingReference[] renderings =
galleryItem.Visualization.GetRenderings(Sitecore.Context.Device, false);
foreach (RenderingReference rendering in renderings)
{
rendering.Settings.DataSource = strDataSource;
this.Controls.Add(
rendering.RenderingItem.GetControl(rendering.Settings));
}
}
}
}
But really, you should just properly implement the Page Editor.