-
Notifications
You must be signed in to change notification settings - Fork 148
Widgets for Developers
In Better CMS there are two types of widgets:
- Content widgets (simple html content that can be used on multiple pages);
- Server widgets;
Content widgets are created via the Better CMS control panel. They are simple to create and function in a very similar way to content editing.
Server widgets are used for the website functionality that needs server side processing.
In the website project add partial view (*.cshtml) with the functionality that is needed - there is nothing special about such view.
Tip: if you would like to add all your widget functionality in to the controller action, than in partial view just call RenderAction. Please, pay attention, that Area needs to be defined.
@{ Html.RenderAction("SomeAction", "SomeController", new {Area = ""}); }
A server widget can have configurable parameters - options that are passed to a *.cshtml view as ViewBag properties. (Currently, these properties can only be a string type.) So, if in a widget registration dialog "WidgetTitle" option is added - in a *.cshtml view the value can be accessible as follows:
<p>Title is @ViewBag.WidgetTitle</p>
Tip: ( will be done from version 1.1.0-betaXX ): PageId can be accessed in widgets also, using ViewBag's magic value bcmsPageId :
<p>Page Id is @ViewBag.bcmsPageId</p>
Currently, there is no magic about template registration - just use front end functionality:
- go to Widgets section in Site settings
- click Register+
- in Basic Properties input title and widget path
- and in Widget Options tab register all the options with default values