DEV Community

Cover image for An Introduction to world of OctoberCMS Widgets
Sapna T
Sapna T

Posted on

An Introduction to world of OctoberCMS Widgets

Highly customizable, easy to use, robust security and breakthrough performance, are a handful of many reasons that works behind the popularity of OctoberCMS. One of the most competitive CMS platforms, OctoberCMS has been a preferred pick for many, against its top-notch competitors. Being an active member of OctoberCMS community ever since 2016,

AddWeb has so far successfully accomplished 5+ projects and contributed 1 plugin. All of these and 500+ man hours of OctoberCMS-ing, we consider us to be eligible enough to share our tips and information surrounding OctoberCMS Development.

Recently, we were working on one of our projects and the thought of the widgets playing an instrumental part in building an OctoberCMS website, crossed our mind. So, let us speak and share something about them today.

What are OctoberCMS widgets?

Widgets are the self-contained blocks of functionality, which helps in solving different tasks. A back-end controller prepares the widget data, along with handling the AJAX requests. It also always have the user interface.

Widgets are useful for both the back-end as well as front-end. Widgets can furthermore be categorized under three main types, as follows:

1).Generic Widgets

2).Form Widgets

3).Report Widgets

Let us now share some details on each of the above-mentioned widget types.

1) Generic Widgets

They are the bundles of functionality, which can be injected to the page.

They act like components and stored inside the widgets folder.

They’re the modular bundles of functionality, supply partials and are given the titled using aliases.

They are the back-end equivalents of front-end components, whose only difference is the use of YAML extension that bank-end widget uses for configuration for binding the backend pages.

The widget classes are saved in the widgets directory, which is a part of the plugin directory.

The directory name matches the widget class name, which is written in lowercase.

Widgets are able to supply the assets and the partials.

2) Form Widgets

They’re the special kind of widgets in OctoberCMS.

They open up the opportunity to create new control types, which can be later used by other plugins/CMS.

They are used for adding new control types to the back-end forms.

They come with features that are commonly used in supplying data for models.

They must be registered in the Plugin.php file.

Form Widget Properties:

There are a few core properties of form widgets, which are used in the form field configuration.

One needs to first define the properties that are configurable on the class and later call the fillFromConfig method, in order to populate them inside the init method definition.

3) Report Widgets

They are the most popular kind of widgets.

They are helpful in adding specific context-based content.

They can be used both, on the back-end dashboard as well as in other back-end report containers.

Report Widget Classes:

Report Widgets classes should extend from the Backend\Classes\ReportWidgetBase class.

Report Widgets classes should override the render method in order to render the widget itself.

Report widgets use partials and a special directory layout.

For complete block of code snippet, move to - OctoberCMS Widegets.

Top comments (0)