ProfileSitecore APIBlogLists Tools Help

Blog


    December 06

    Linking items and databases

    The following will apply to the release build of Sitecore 5.1.1
     
    In Sitecore you can create special 'proxy' items that serve as links between different items. The items being linked may come from different databases.
     
    For instance, say I have the following structure:
     
      A
      |-B
      |-C
        |-D
        |-E
          |-F
       
    Now I want to expose E and its children below B such that E can be found both below B and below C.
     
    The way to do it is:
    1. Start the Sitecore Shell
    2. Select 'Deactivate proxies' from the database menu (in the lower right corner next to the clock)
    3. Open the Content Editor
    4. Navigate to B
    5. Create a new item below B from the template 'Proxy'
    6. Fill in the field 'Target item' with the ID of E
    7. Save
    8. Select 'Activate proxies' from the database menu
    E will now appear below B and its data and children will be shown when it is selected. The E below B is shown in a different color to signify that it is only a 'shadow' of the real E.
     
      A
      |-B
        |-E'
          |-F'
      |-C
        |-D
        |-E
          |-F

     
    All operations on the E shadow item (E') will be redirected to the real E. For instance if you change any data in E' and select Save then the data will be saved to E. E' has no data of its own.
     
    Even the Delete operation works on the real E so be careful!
     
    There are a few exceptions to the rule of redirection:
    1. If you copy the root of a shadow tree to another location, it is the underlying proxy item that is copied
    2. If you move the root of a shadow tree to another location, it is the underlying proxy item that is moved
    3. If you delete the root of a shadow tree, only the proxy item will be deleted.

    Linking across databases

    To make links between databases, follow the same instructions as above, but specify a database name in the 'Target database' field of the proxy item. When proxies are activated, the shadow items will be retrieved from the target database.
     
    Please note that to protect the host database, all shadow items will be given unique (but static) IDs. Therefore you can link the same items multiple times in the same host database without ID collisions.

    Children

    It is possible to exclude the children of a linked item by selecting 'Exclude children' on the proxy item.

    API support for linked items

    The shadow ID will be exposed in the Item.ID property. If you need the 'real' ID of an item, you can use:
     
      Item.InnerData.Definition.ID
     
    Also, there are some properties in the RuntimeSettings object that supports working with linked items. Note that the settings only applies when proxies are activated.
    • Item.Runtimesettings.IsShadow: Specifies if an item is a shadow item.
    • Item.Runtimesettings.IsProxy: Specifies if an item is a proxy (ie. it is the root of a shadow tree).
    • Item.Runtimesettings.IsVirtual: Specifies if an item is either a shadow or a proxy
    • Item.Runtimesettings.IsExternal: Specifies if an item is from another database than the host database
    • Item.Runtimesettings.OwnerDatabase: The database that owns the item. The Item.Database property will always return the host database. To get the 'real' database owning an item use this property instead.
    In a future version we will expose more of the 'shadow' API.