Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few scenarios that occur to me, not sure which one is yours:</p> <p><strong>1. Current Item is the Only Item</strong></p> <p>If you are doing something like a details page that shows a product or a services item's full details, the Sitecore.Context.Item call will get you the current item that is in context, in most cases based on the current item path in the URL (there are ways to change the context, but let's ignore those fringe cases for now). Then you can just bind your fields or extract values just as you would any other time.</p> <p><strong>2. Binding to a list of Items</strong></p> <p>If you are doing something like a list of "things" (i.e. a .NET repeater bound to a list of items that could be Product or Services) and want to display each one with a user control. A few options:</p> <ol> <li>Add a property to your control (something like "DataSource") and during your repeater databinding in your sublayout set the user control Datasource property (or do so in the repeater markup)</li> <li>Extract the properties you want from the Item during the repeater databinding in your sublayout and pass that to different properties on your user control.</li> </ol> <p><strong>3. Driven by Datasource</strong></p> <p>If you are running a sublayout which is configured to have a Datasource, then you can't use the context item as that will refer to the item bound to the "page" being displayed, and not the particular component you are working on. In this case, you'll need code like the following to extract the datasource from the current sublayout:</p> <pre><code>var dataSourceId = ((Sitecore.Web.UI.WebControl)Parent).DataSource; </code></pre> <p>(Note: You may want to do some error handling on the above code to prevent null reference errors)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload