# Plugin Variablen an Less übergeben

**URL:** <https://forum.shopware.com/t/plugin-variablen-an-less-uebergeben/93731>\
**Category:** Shopware 5\
**Created:** [30. März 2022 um 15:27 UTC](https://forum.shopware.com/t/plugin-variablen-an-less-uebergeben/93731 "2022-03-30T15:27:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![realconvis](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@realconvis](https://forum.shopware.com/u/realconvis)\
**Post date:** [30. März 2022 um 15:27 UTC](https://forum.shopware.com/t/plugin-variablen-an-less-uebergeben/93731/1 "2022-03-30T15:27:00Z")

</div>

Was ist aktuell der Beste weg um Variablen die ich in einem Plugin definiere Less zur Verfügung zu stellen?

Ist es immer noch so etwas in der Art in einem Subscriber:

```auto
public static function getSubscribedEvents()
    {
        return [
            'Theme_Compiler_Collect_Plugin_Less' => 'onCollectPluginLess'
        ];
    }

    public function onCollectPluginLess(\Enlight_Event_EventArgs $args):ArrayCollection
    {
        $less = new LessDefinition(
        //configuration
            [
                'NewLessVar' => 'foo';
            ],
            //less files to compile
            array(
                dirname( __DIR__ ) . '/Resources/views/responsive/frontend/_public/src/less/all.less'
            ),
            //import directory
            dirname( __DIR__ )
        );

        return new ArrayCollection(array($less));
    }

```

---

<div class="post-metadata">

**Author:** ![sonic](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/sonic/32/25728_2.png) [@sonic](https://forum.shopware.com/u/sonic)\
**Post date:** [31. März 2022 um 07:25 UTC](https://forum.shopware.com/t/plugin-variablen-an-less-uebergeben/93731/2 "2022-03-31T07:25:33Z")

</div>

Auch bei 5.7.7 mache ich das noch so. Glaube nicht, dass sich da ein weiterer Weg aufgetan hat.  
Ich binde aber nur die Vars ein, die mit „less“ anfangen.

mal aus einem Plugin

```php
public function onCollectLessFiles(\Enlight_Event_EventArgs $args)
    {
        $pluginDir = $this->getPath();
        $pluginConfig = $this->container->get('shopware.plugin.cached_config_reader')->getByPluginName($this->getName(),$args->getShop());

        $variables = [];
        foreach ($pluginConfig as $key => $value) {
            if (substr($key,0,4) == "Less") {
                $variables[$key] = $value;
            }
        }
        $less = new LessDefinition(
            //configuration
            $variables,
            //less files to compile
            [$pluginDir . '/Resources/views/frontend/_public/src/less/all.less'],
            //import directory
            $pluginDir
        );

        return new ArrayCollection([$less]);
    }

```

Subscriber:

```php
'Theme_Compiler_Collect_Plugin_Less' => 'onCollectLessFiles' 

```

---

<div class="post-metadata">

**Author:** ![realconvis](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@realconvis](https://forum.shopware.com/u/realconvis)\
**Post date:** [31. März 2022 um 10:54 UTC](https://forum.shopware.com/t/plugin-variablen-an-less-uebergeben/93731/3 "2022-03-31T10:54:50Z")

</div>

Danke für die Antwort.

Ich hab das mal noch ein wenig schlanker gemacht, da meine LESS Dateien in der Ordnerstruktur so enthalten sind, das es anscheinend nicht nötig ist die Pfade mit zu übergeben.  
Und ich muss sagen, es funktioniert 🙂

```auto
class Less implements SubscriberInterface
{

    public static function getSubscribedEvents(): array
    {
        return [
            'Theme_Compiler_Collect_Plugin_Less' => 'onCollectPluginLess'
        ];
    }

    public function onCollectPluginLess(\Enlight_Event_EventArgs $args): ArrayCollection
    {
        $less = new LessDefinition(
            [
                'NewLessVar' => 'foo'
            ],
        );

        return new ArrayCollection(array($less));
    }
}

```
