otakoyi/widgets

Asgardcms CMS Widgets

dev-master 2018-09-28 14:46 UTC

This package is not auto-updated.

Last update: 2024-04-22 05:39:01 UTC


README

This simple package allows create multiple widgets and widgets groups and manage selected in CMS.

With this module, you can create a set of widgets and keep logic in the controllers and not in the template. You can group widgets into groups, so you do not need to hard code in the template of your module. Just call the platform on the key and it will display the registered widgets in it. You can also pass parameters to the pad. When you turn off the widget, your module code will not be broken. You can also call a widget by name with params.

In the future, UI interface is provided in the backend area, which will allow managing the registered widgets as in WordPress. We also plan to integrate widget management into the templates of your modules in the backend.

It register two collection in service provider;

...
    // all widgets will be stored  in widgets collection 
    $this->app->instance('widgets', new WidgetsCollection());
     
    // all places will be stored in  widgetsGroup collection
    $this->app->instance('widgetsGroup', new WidgetsGroupCollection());
...    

## How to use.

  1. Create widget in Modules\Example\Widgets

Widget example:

<?php 
namespace Modules\Example\Widgets;

use Modules\Widgets\BaseWidget;

/**
* Class MyWidget
* @package App\Widgets
*/
class Example extends BaseWidget
{
    public function __construct()
    {
        parent::__construct('My first widget');
    }

    public function form($instance)
    {
        // TODO: Implement form() method.
    }

    public function show($options, $instance)
    {
        return "---------- Example widget::show. ". var_export($options, 1);
    }
}
  1. Register widget in service provider in boot() method
        // register widget
        $instance = app('widgets')->add(\Modules\Example\Widgets\Example::class);
        
        // show it on place
        app('widgetsGroup')->assignToGroup('some.place', $instance);
  1. Show widget by name

     @widget("Modules.Example.Widgets.Example", ['foo' => $bar])
    
  2. Display all widgets registered in place

    @widgets("some.place", ['foo' => $bar])