Skip to content

Ternary expressions without true fork work in PHP Twig, fail in twig.js #903

Open
@stuartlangridge

Description

@stuartlangridge

php -r "require_once './vendor/autoload.php'; \$loader = new \Twig\Loader\ArrayLoader(['index' => '{{myvar ? : 0}}']); \$twig = new \Twig\Environment(\$loader); echo \$twig->render('index', ['myvar' => FALSE]);"

This outputs "0".

node -e 'const Twig = require("twig"); console.log(Twig.twig({data: "{{ myvar ? : 0 }}"}).render({myvar: false}))'

This outputs

Error compiling twig template undefined:
TwigException: Twig.expression.type.operator.binary cannot follow a Twig.expression.type.operator.binary at template:6 near ':...'

I'm not sure that ternary expressions of the form myvar ? : "falsy output" are a good idea, but real Twig supports them, so this library really ought to as well.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions