Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
steevanb opened this issue Apr 13, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@steevanb
Copy link

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
Copy link
Member

erkens commented Apr 15, 2024

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)

@erkens erkens self-assigned this Apr 15, 2024
@erkens erkens added the question Further information is requested label Apr 15, 2024
@steevanb
Copy link
Author

Hi,

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

PHP: 8.3, Symfony: 7.0, Twig: latest

@erkens
Copy link
Member

erkens commented Apr 15, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants