amteich / kirby-twig

Twig templating support for Kirby CMS
MIT License
48 stars 12 forks source link

The documentation for the autoescape option is incorrect #30

Closed MoritzLost closed 2 years ago

MoritzLost commented 2 years ago

The options documentation includes this example:

// Disable autoescaping or specify autoescaping type
// http://twig.sensiolabs.org/doc/api.html#environment-options
'amteich.twig.autoescape' => true

But setting the option to true causes an error:

call_user_func(): Argument #1 ($callback) must be a valid callback, no array or string given

That's because the option is passed directly as the autoescape option to the Twig environment:

'autoescape' => option('amteich.twig.autoescape', 'html'),

But Twig expects either a string with the default escaping strategy or false to disable autoescaping for that parameter, passing true is not supported.

To fix this, the plugin could check if the option is true and convert it to html, which would be my preferred solution:

$autoescape = option('amteich.twig.autoescape', 'html');
if (true === $autoescape) {
    $autoescape = 'html';
}

If this is not in line with the plugin's intended usage, the documentation at least shouldn't show an invalid option:

// either
'amteich.twig.autoescape' => false

// or
'amteich.twig.autoescape' => 'html'
seehat commented 2 years ago

Thanks for letting me know. I fixed the documentation.