How to render content item in widget

2025/02/26 4:21 AM

Hello Community,

I have created some content types and from that some content items in content hub. now i want these content items to be rendered in widget. I have already created widget properties class from IWidgetPropprties and added some fields to it i am not sure if kentico allows to render content items inside the widget.

Also wanted to know what should be the practises for creating/rendering the widget.


Environment

  • Xperience by Kentico version: [30.0.1]
  • .NET version: [8]

Answers

2025/02/26 8:14 AM

For things like this, the documentation and guides are your best friends!

Regarding your question, you’re most likely looking for the Combined content selector to be added to your widget properties. This lets you select content items from the content hub. In your implementation, you can then access the selected items, process them as needed, and render them.

The Combined content selector form component attribute is called ContentItemSelectorComponent, so that’s where you should start. I’d also recommend setting up the Dancing Goat sample site locally to see it in action. A couple of widgets use it, so you can check out their code for inspiration.

For general best practices and working with widgets, the official guides are a great resource!

https://docs.kentico.com/guides/development/page-builder/build-simple-cta-widget

https://docs.kentico.com/guides/development/page-builder/define-advanced-widget

2025/02/26 8:21 AM

You can find a summarize of all components you can use in XbyK here: https://docs.kentico.com/developers-and-admins/customization/extend-the-administration-interface/ui-form-components/reference-admin-ui-form-components

I think you want the Combined content selector.

There are some more selectors you could use to achieve this, e.g. content item folder selector or smart folder selector.

Access the properties in the view component when creating the view model for your widget rendering.

To answer this question, you have to login first.