1. Go to this page and download the library: Download artisancms/widgets library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Widgets;
use ArtisanCMS\Widgets\AbstractWidget;
class RecentNews extends AbstractWidget
{
/**
* The configuration array.
*
* @var array
*/
protected $config = [];
/**
* Treat this method as a controller action.
* Return view() or other content to display.
*/
public function run()
{
//
return view("widgets.recent_news", [
'config' => $this->config,
]);
}
}
public function placeholder()
{
return "Loading...";
}
class RecentNews extends AbstractWidget
{
/**
* The number of seconds before each reload.
*
* @var int|float
*/
public $reloadTimeout = 10;
}
/**
* Async and reloadable widgets are wrapped in container.
* You can customize it by overriding this method.
*
* @return array
*/
public function container()
{
return [
'element' => 'div',
'attributes' => 'style="display:inline" class="artisancms-widget-container"',
];
}
class RecentNews extends AbstractWidget
{
/**
* The number of minutes before cache expires.
* False means no caching at all.
*
* @var int|float|bool
*/
public $cacheTime = 60;
}
// add several widgets to the 'sidebar' group anywhere you want (even in controller)
Widget::group('sidebar')->position(5)->addWidget('widgetName1', $config1);
Widget::group('sidebar')->position(4)->addAsyncWidget('widgetName2', $config2);
// display them in a view in the correct order
@widgetGroup('sidebar')
//or
{{ Widget::group('sidebar')->display() }}
bash
php artisan make:widget RecentNews
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.