Skip to content Skip to footer navigation
You are reading the Statamic 6 Alpha docs. ๐Ÿ‘€

Building Widgets

Generating a widget

You can generate a widget with a console command:

php please make:widget LocalWeather

This will automagically create a class in app/Widgets and a Blade view in resources/views/widgets.

The PHP class is responsible for returning the view and the view is responsible for what the user sees on the page.

// app/Widgets/LocalWeather.php
<?php
namespace App\Widgets;
use Statamic\Widgets\Widget;
class LocalWeather extends Widget
{
public function html()
{
return view('widgets.local_weather');
}
}
<ui-widget title="LocalWeather">
<div class="px-4 py-3">
<p>๐Ÿ‘‹ Hello world!</p>
</div>
</ui-widget>

The <ui-widget> component accepts a title and an optional icon prop.

Configuring

Widgets can be added to the dashboard by modifying the widgets array in the config/statamic/cp.php file.

// config/statamic/cp.php
'widgets' => [
'getting_started',
[
'type' => 'local_weather',
'width' => 100,
],
],