phug-php / phug

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

Shared variables lost when cache enabled #19

Closed Illvili closed 6 years ago

Illvili commented 6 years ago

Hello,

I encountered an issue with the following code:

<?php
use Pug\Pug;

include 'vendor/autoload.php';

$pug = new Pug([
    'shared_variables' => [
        'foo' => 123
    ],
    'cache' => __DIR__ . '/cache'
]);

$pug->display('p=foo');

I expected to get:

<p>123</p>

But I actually get:

<p></p>

So I found something here: Phug\Renderer\Partial\AdapterTrait line 94

$adapter->displayCached($path, $input, $getSource, $parameters);

change it to:

$adapter->displayCached($path, $input, $getSource, $this->mergeWithSharedVariables($parameters));

could solve this.

Does this change cause someting error?

Additional, at first I try to use Phug with js style expression, when cache enable it fail with

You cannot use "cache_dir" option with Phug\Renderer\Adapter\EvalAdapter because this adapter does not implement Phug\Renderer\CacheInterface

Thanks!

kylekatarnls commented 6 years ago

Hello,

Indeed $parameters should always be used with mergeWithSharedVariables before a rendering. I will fix it.

Can you give me the PHP code of your second error (with Phug)?

kylekatarnls commented 6 years ago

You second problem should now also be fixed by updating with composer update

Illvili commented 6 years ago

Every thing work fine, thanks!