> For the complete documentation index, see [llms.txt](https://akyos.gitbook.io/book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://akyos.gitbook.io/book/prestashop/modules/widget.md).

# Widget

### Introduction

Les widgets sont une autre manière d’afficher le contenu d’un module directement depuis un template, sans passer uniquement par la logique classique “hook + module greffé sur ce hook”.&#x20;

### Rendre le module "Widget Complient"

Pour rendre le module widget-complient, il faut 2 choses :&#x20;

#### Implémenter l'interface

`PrestaShop\PrestaShop\Core\Module\WidgetInterface`

#### Déclarer les méthodes obligatoires

Dès qu'un module implémente l'interface WidgetInterface, deux méthodes doivent être déclarées :

```php
public function renderWidget($hookName, array $configuration);
public function getWidgetVariables($hookName, array $configuration);
```

Le structure du module donne donc ceci :&#x20;

<pre class="language-php"><code class="lang-php"><strong>&#x3C;?php 
</strong><strong>
</strong><strong>if (!defined('_PS_VERSION_')) {
</strong>    exit;
}

use PrestaShop\PrestaShop\Core\Module\WidgetInterface;

class ExempleModule extends Module implements WidgetInterface
{
    public function __construct()
    {
        $this->name = 'examplemodule';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'akyos.com';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = [
            'min' => '1.7.6',
            'max' => _PS_VERSION_,
        ];
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->trans('Name of my module', [], 'Modules.Exemplemodule.Admin');
        $this->description = $this->trans('Description o my module', [], 'Modules.Exemplemodule.Admin');
        $this->confirmUninstall = $this->trans('Are you sure you want to uninstall this module?', [], 'Modules.Exemplemodule.Admin');
    }

    public function install()
    {
        return parent::install();
    }

    public function uninstall()
    {
        return parent::uninstall();
    }
    
    public function renderWidget($hookName = null, array $configuration = [])
    {
        $templateFile = 'module:' . $this->name . '/views/templates/front/widget.tpl';

        return $this->fetch($templateFile);
    }

    public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        return [
            'variable' => 'test',
        ];
    }

    public function isUsingNewTranslationSystem(): bool
    {
        return true;
    }
}
</code></pre>

### Appeler le widget

Pour appeler un widget depuis le thème il suffit de faire ceci : `{widget name='examplemodule'}`
