lelyfoto / twig-instanceof

Adds InstanceOf Expression as Twig Extension
MIT License
3 stars 3 forks source link

Attribute "value" does not exist for Node "Twig\Node\Expression\FunctionExpression" #2

Open steevanb opened 2 months ago

steevanb commented 2 months ago

Hi,

Thanks for your awesome extension, i will never understand why it's not in Twig...

But i have this error: 2024-04-13_17h46_59

With this code in my twig template:

{% if move is instanceof(getAttackFqcn()) %}

Here is the dump before the exception is throwned:

# vendor/twig/twig/src/Node/Node.php
    public function getAttribute(string $name)
    {
        if (!\array_key_exists($name, $this->attributes)) {
            dd($this->attributes);
            throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, static::class));
        }

        return $this->attributes[$name];
    }
^ array:2 [
  "name" => "getAttackFqcn"
  "is_defined_test" => false
]
erkens commented 2 months ago

I have not (yet) tested it with a function to be honest, but first thing that comes to mind: is the return value of your "getAttackFqcn" function an escaped string?

Also, please specify which version of PHP and Twig (and Symfony if applicable)

steevanb commented 2 months ago

Hi,

getAttackFqcn() return Attack::class, I can espace it if needed.

PHP: 8.3, Symfony: 7.0, Twig: latest

erkens commented 2 months ago

Yes, please escape the \ from the namespace, a simple addslashes(Attack::class) should be enough.

The problem is that Twig attributes can't have unescaped backslashes (afaik)