How we can build accordion widget with multiple accordion item with rich-text-editor under the item?

Surajit Das asked on November 2, 2023 10:50

How we can build accordion widget with multiple accordion item with rich-text-editor under the item?

Recent Answers


Brenden Kehren answered on November 3, 2023 16:25

I'd suggest using content only page types. Assume you're using the Bootstrap accordion for simplicity sake. Create an Accordion page type. Maybe add some properties to define the overall accordion. For example, accordion ID, title, item open icon, item closed icon. Accordion ID will be used when defining the accordion as bootstrap requires.

Secondly, create another page type called Accordion Item. This content type would have properties like ItemTitle, ItemContent, etc. Set the Accordion item to only be available under the Accordion page parent (allowed page types).

Retrieve your Accordion page type data, then retrieve all the accordion items directly below that accordion page (children). Loop through the children and output what is necessary for that accordion item. Lastly at the end of that accordion item loop, you can render the WYSIWYG editor manually following the Kentico documentation. Instead of the Form identifier, you will use this identifier for editor SystemComponentIdentifiers.RICH_TEXT_WIDGET_IDENTIFIER.

All that being said, I'm assuming you just wanted to create the accordion items dynamically and add titles and content right in the page builder. What I provided above will be a much better solution and allow you to create an accordion widget that selects the path of the accordion parent then display all the children as items. The accordion item content type can have the "content" added as rich text. Then you wouldn't need to register that standalone widget. The key is using strongly typed content and not just adding a bunch of rich text all over the site.

0 votesVote for this answer Mark as a Correct answer

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