How to create a dynamic source for a multilist in Sitecore?

I have the following content tree structure:

  • home
    • Products
      • Product a
      • Product B
    • The organization
      • Org 1
      • Org 2
        • Org Config X
        • Org Config Y

Each Organization under Organizations has a field called "Associated Products", which is a multi-sheet. This informs the system that Products come with every Organization. The Org Config data template has a Favorite Products field. When I add a new Org Config content item (which always lives directly below the Organization), I would like to be able to limit the items displayed in the Selected Products field (which is a multi-sheet) to display only products that are already associated with the parent organization. I think there might be a way to do this using Sitecore Query, but I can't figure it out. Any ideas?

+4
source share
2 answers

With Sitecore, I figured it out. Basically you need to create a custom control that inherits from MultilistEx. Then you need to override the DoRender () event. Before calling base.DoRender (), you must change the source (this.Source) to use the Sitecore request. I used to try to do this in the OnLoad event. So now my code is as follows:

public class CustomMultiList : MultilistEx { private void ExcludeItems() { ...custom code here that builds a list of Item IDs to exclude from the Multilist source... ...list should look like this "@@id != 'some guid' and @@id != 'some guid' and so forth... ...you could also build a list of item ids to include. Any Sitecore query will do... ...you can use this.ItemID to get a reference to the current item that is being edited in the Content Editor... this.Source = "query:" + this.Source + "/*[" + myListOfItemIdsToExclude + "]"; } protected override void DoRender(output) { this.ExcludeItems(); base.DoRender(output); } } 
+2
source

Source: https://habr.com/ru/post/1478857/


All Articles