phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
62 stars 3 forks source link

How to integrate Phug as a plugin into a framework? #45

Closed OnkelTem closed 5 years ago

OnkelTem commented 5 years ago

I'm developing a PHP data processing framework and I'm gonna add Phug as a plugin. When a plugin runs, it creates instances of underlying workers, e.g. twig example:

public function initialize() {
    $this->twig = new Environment(new ChainLoader($this->loaders), $this->options ?? []);
}
function getValue($context) {
    return $this->twig->load('template')->render($context);
}

But with Phug I don't see how can I create an instance of its worker. The Phug class is static, setting options seems to set them globaly. But... why? Shouldn't it be an isolated thing, or what is reason of working with globals/singletons?

I tried to look up for implementations in other frameworks but they seem to be not using phug at all.

kylekatarnls commented 5 years ago

Phug\Phug is just a facade. You can call instances of Phug\Renderer (or Pug\Pug if using pug-php, pug-symfony, laravel-pug, etc.)

I tried to look up for implementations in other frameworks but they seem to be not using phug at all.

They all use Phug, because pug-php itself uses it since its version 3. And most examples with Pug\Pug will also work with Phug\Renderer, Pug\Pug extends Phug\Renderer and just add some options for backward-compatibility with pug-php 2 and add JS-style expressions (js-phpize).

OnkelTem commented 5 years ago

I see, thank you very much. So to Renderer... And yeah, now it does make sense.