Retrieving Items

Retrieving Items

This snippet uses an index to reference the item’s field

  • Accesses the raw value of the field
  • Returns an empty string if the field does not exist or the field value is null
  • Does not generate inline editing controls for the Page Editor
  • Useful for simple fieldtypes

C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;

Sitecore.Data.ID[] ids = Sitecore.Data.ID.ParseArray(item["fieldname"], false);

foreach (Sitecore.Data.ID id in ids)

{

      Sitecore.Data.Items.Item target = Sitecore.Context.Database.GetItem(id);

      // Do something with the id....

}


XSLT Rendering Code

<xsl:for-each select="sc:Split('FieldName',$sc_currentitem)">

      <xsl:for-each select="sc:item(text(),$sc_currentitem)">

             <xsl:value-of select="@name" />

             <br />

      </xsl:for-each>

</xsl:for-each>