Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Sitecore lookup fields

Modified: 2008/02/22 15:26 by jeroenoliemans - Categorized as: Sitecore


Edit

Sitecore lookup fields

Most Sitecore websites make use of lookup fields in the backend to make the site more dynamic. Sitecore offers 3 lookup field options:
  1. Checkbox
  2. Checklist
  3. Lookup


Edit

Create a lookup field

  1. Create a set of items in the item tree nested in a folder, for example myLookup
    • red
    • green
    • blue
  2. Create a template with a lookup field with the name “ColorLookup” in the source field of the template lookup field enter the path to the folder in the item tree containing the lookup values. For example: /sitecore/content/myLookup/
  3. The page based on this template now contains a pulldown field with the color values.


  4. Edit

    Access a lookup field

    The first misconception is the fact that accessing the lookup field value does not result in one of the color values.

    Edit

    For example



    The result will be the guid of the color item in the item tree

    Retrieving the name of the selected option for the lookup field

    We will use the guid to make a reference to the color item in the item tree, and acces the name of this item.

    1. Create a variable of the guid selection HTML:
    <xsl:variable name="selectedGuid" select="sc:fld( 'ColorLookup', . )" />

    2. Create a variable for the selected color item HTML:
    <xsl:variable name="selectedColor" select="sc:item( $selectedGuid, .)" />

    3. Read the name of the item HTML:
    <xsl:value-of select="$selectedColor/@name" />

    It is also possible to set all the steps in a single xsl line

    HTML:
    <xsl:value-of select=" sc:item(sc:fld ( 'ColorLookup' , . ), .)/@name" />

 © Evident Interactive BV