Creating widget zones programatically

Petr Nejedly asked on April 12, 2021 09:37

Hi,

I need to create a widget, where editors can define a list of Tabs (e.g. 1 to 5 Tabs), and I need them to be able to add a nested widget into every individual Tab.

So I am wondering, is there a way how to create widget zones programmatically, so I could iterate through the list of Tabs and create one widget zone for every individual Tab?

Thanks, Petr

Correct Answer

Arjan van Hugten answered on April 12, 2021 10:30

If it's possible for you to make the tabs configuration a section you could use that. The section will have a configurable number of tabs and inside the view of the section the number of tabs are rendered with a for loop into widget zone's.

Something like this:

<div class="tabs">
  @{
    for (int i = 0; i < Model.NumberOfTabs; i++)
    {
      <div class="tab">
        @Html.Kentico().WidgetZone()
      </div>
    }
  }
</div>
1 votesVote for this answer Unmark Correct answer

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