<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sublayouts &#8211; blog.boro2g .co.uk</title>
	<atom:link href="https://blog.boro2g.co.uk/tag/sublayouts/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.boro2g.co.uk</link>
	<description>Some ideas about coding, dev and all things online.</description>
	<lastBuildDate>Thu, 16 Jun 2011 21:52:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.8</generator>
	<item>
		<title>Take control of your sublayouts</title>
		<link>https://blog.boro2g.co.uk/take-control-of-your-sublayouts/</link>
					<comments>https://blog.boro2g.co.uk/take-control-of-your-sublayouts/#respond</comments>
		
		<dc:creator><![CDATA[boro]]></dc:creator>
		<pubDate>Wed, 15 Jun 2011 13:55:15 +0000</pubDate>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[sublayouts]]></category>
		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=59</guid>

					<description><![CDATA[<p>There are several options available when setting up which data feeds into your sublayouts or renderings within Sitecore. Typically we work with sublayouts since they fit the programming style used in-house. When you add a presentation component to a page you can configure data in a manner of ways: In this example we have setup [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.boro2g.co.uk/take-control-of-your-sublayouts/">Take control of your sublayouts</a> appeared first on <a rel="nofollow" href="https://blog.boro2g.co.uk">blog.boro2g .co.uk</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There are several options available when setting up which data feeds into your sublayouts or renderings within Sitecore. Typically we work with sublayouts since they fit the programming style used in-house.</p>
<p>When you add a presentation component to a page you can configure data in a manner of ways:</p>
<p><a href="http://blog.boro2g.co.uk/wp-content/uploads/2011/06/sublayout-parameters.png"></a><a href="http://blog.boro2g.co.uk/wp-content/uploads/2011/06/sublayout-parameters.png"><img fetchpriority="high" decoding="async" class="aligncenter size-medium wp-image-62" title="sublayout parameters" src="http://blog.boro2g.co.uk/wp-content/uploads/2011/06/sublayout-parameters-300x195.png" alt="" width="300" height="195" srcset="https://blog.boro2g.co.uk/wp-content/uploads/2011/06/sublayout-parameters-300x195.png 300w, https://blog.boro2g.co.uk/wp-content/uploads/2011/06/sublayout-parameters.png 686w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>In this example we have setup rendering parameters for &#8216;Section Image Header&#8217; (the items that feed this dropdown are content items elsewhere in the content tree). Alternatively you can explicitly set the &#8216;Data Source&#8217;.</p>
<p>When coding your sublayouts, its simple to extract information from either the rendering parameters or the &#8216;Data Source&#8217; field using the following examples.</p><pre class="crayon-plain-tag">//this is your ascx code behind
Sublayout sublayout = this.Parent as Sublayout;

if (sublayout != null)
{
    //the ascx path
    string sublayoutPath = sublayout.Path;    

    Placeholder placeholder = sublayout.Parent as Placeholder;

    //the sitecore placeholder key
    string placeHolderKey = &quot;&quot;;

    if (placeholder != null)
    {
        placeHolderKey  = placeholder.ContextKey;
    }    

    //the data source item
    Item item = Sitecore.Context.Database.GetItem(sublayout.DataSource);

    if (item == null)
    {
        //handle appropriately
    }
    else
    {
        //use the item
    }

    //the sublayout parameters
    NameValueCollection parameters = WebUtil.ParseUrlParameters(sublayout.Parameters);
}</pre><p>To then access the &#8216;Section Image Header&#8217; rendering parameter you could query:</p><pre class="crayon-plain-tag">string sectionImageHeader = parameters[&quot;Section Image Header&quot;];</pre><p>One disadvantage with using parameters to setup the data into sublayouts is that the links database doesnt honour the relationship. See <a href="http://blog.boro2g.co.uk/where-is-shared-content-used/">where is shared content used</a> for help with this.</p>
<p>Rather than needing the code shown above in every sublayout you can create a base classes to expose the data source and parameters as properties and methods:</p><pre class="crayon-plain-tag">public class SUserControl : UserControl
{
    public Item ItemDataSource { get; set; }
    public string GetParameter(string key);

    public string PlaceholderKey();
    public string SublayoutAscx();</pre><p>Another tip to consider, you can setup your sublayouts with an attribute to automatically use the rendering parameters as the sublayouts data:</p><pre class="crayon-plain-tag">[SRenderingParameter(&quot;Section Image Header&quot;)]
public partial class SectionImageHeader : SUserControl</pre><p>In this example the sublayout will know to take its data from the item related in the &#8216;Section Image Header&#8217; rendering parameter.</p>
<p>The post <a rel="nofollow" href="https://blog.boro2g.co.uk/take-control-of-your-sublayouts/">Take control of your sublayouts</a> appeared first on <a rel="nofollow" href="https://blog.boro2g.co.uk">blog.boro2g .co.uk</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.boro2g.co.uk/take-control-of-your-sublayouts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
