2

I am using Sitecore 9. I am having a problem trying to populate the droptree in the template(source). The template ID for the Apple, Banana and Peach is {AB86861A-6030-46C5-B394-E8F99E8B87DB} and the template id for the Apple Skin, Banana Skin,Peach Skin is {3FFD8425-4652-4BFE-9D8D-5CC1AE2D24A2} This is how my Sitecore structure looks like

/sitecore/content/Global/My Manager/MyFruits/

under Myfruits

  • FruitOne

    • Apple
      • Apple Skin
  • FruitTwo

    • Banana
      • Banana Skin
  • FruitThree

    • Peach
      • Peach Skin

I only want to show Apple Skin, Banana skin and Peach skin in the droptree.

I am able to show all three using a Droplist or Droplink using this query

query:/sitecore/content/Global/My Manager/MyFruits//*[@@templateid = '{3FFD8425-4652-4BFE-9D8D-5CC1AE2D24A2}']

If i use the same query for droptree i only get the first one(Apple Skin). I don't get all three.

I have tried using

query:./ancestor-or-self::*[@@templatename='Fruity']/sitecore/content/Global/My Manager/MyFruits

it does not work.

0

2 Answers 2

0

OOTB Sitecore will not give you this type of filtering using DropTree. Droptree shows items as a tree view instead of showing them as the dropdown. The user is allowed to select a single item at a time. It shows a complete Sitecore tree if the source is not provided at the time of field declaration or incorrect source path. The source can be XPath Query or GUID and Item Path.

To fix your particular problem we have multiple options -

  • Change your field type to Drop link it will show you the complete list as dropdown
  • Use the drop tree field which will show you a complete tree node based on your source but add custom validation for the required template type item. using this, you will not be able to select another item in the list.
  • Create a custom field type based on your requirement
  • Use multiroot treelist or treelist field and add custom validation of one item-only selection.

There could be some better approaches to fix this issue from different people here, but this is what I am thinking

1

You can also use TreeList instead of DropTree due to limited options. The TreeList allows users to select descendants of the home item that are based on either the data template named Section or the data template named Page:

DataSource=/Sitecore/Content/Home&IncludeTemplatesForSelection=section,page

For your requirement, you can use the following options of TreeList.

IncludeTemplatesForDisplay: Users can only navigate items based on this comma-separated list of data template names and IDs.

IncludeTemplatesForSelection: Users can only select items based on this comma-separated list of data template names.

To use other options, you can refer to this article.

https://doc.sitecore.com/xp/en/developers/90/sitecore-experience-manager/controlling-the-list-of-items-in-a-selection-field.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.