Restricting the dynamic data source in the widget properties

Alexander Dev asked on April 7, 2022 15:28

Assume that we have a number of conferences. For each conference, we have a separate page in Kentico and a number of Article subpages. The page structure in Kentico is as follows:

Conferences
    Conference1
        Article1
        Article2
    Conference2
        Article3
        Article4

On the conference page Conference2, we want to place a widget that shows a preview of an article related to this conference (Article4). In the widget properties, we have a drop-down list to a dynamic data source as described here: https://docs.xperience.io/developing-websites/form-builder-development/developing-form-components/using-a-dynamic-data-source-with-selector-components

In the selector component CustomDropDownComponent we have:

   DocumentQuery query = DocumentHelper.GetDocuments("DancingGoatMvc.Article")
                        .Path("/Conferences/", PathTypeEnum.Children)
                        .Columns("DocumentName", "DocumentGUID")
                        .OnSite("DancingGoatMvc")
                        .Culture("en-us")
                        .LatestVersion();

The path is hard-coded to /Conferences/ and the query lists all articles from the Conference1 and Conference2. We can have hundreds of articles and conferences. The drop-down list can be very long and confusing.

Since we place the widget on the Conference2 page, how can we restrict the drop-down list to suggest only the articles from the conference2?

Recent Answers


Eugene Paden answered on April 8, 2022 15:07

In your component's model, include a property for the section and just add it in the Path of your documentQuery, e.g.,

.Path($"/Conferences/{Section}", PathTypeEnum.Children)

0 votesVote for this answer Mark as a Correct answer

Alexander Dev answered on April 12, 2022 14:29

Eugene Paden, thanks for the suggestion. How can I set the property Section programmatically from my widget controller? I have only GetProperties() method, but no SetProperties() or similar.

0 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on April 12, 2022 15:45

Can you share your component's full code?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.