Cms: Twig\Error\RuntimeError - Variable "forms" does not exist.

Created on 5 Aug 2020  Â·  12Comments  Â·  Source: craftcms/cms

Description

Twig Runtime Error – Twig\Error\RuntimeError
Variable "forms" does not exist.
Stacktrace.txt

Steps to reproduce

  1. Install Craft CMS
  2. Navigate to /admin/myaccount

Additional info

  • Craft version: 3.4.30
  • PHP version: 7.0.2
  • Database driver & version: Mysql 5.6.48
  • Plugins & versions: None
bug

Most helpful comment

I was able to repro with just twig. I've filed https://github.com/twigphp/Twig/issues/3385

All 12 comments

Are you sure you are on 3.4.30 and not 3.5.0?

Here’s the full error in your stack trace:

Twig\Error\RuntimeError: Variable "forms" does not exist. in /usr/local/apache2/htdocs/vendor/craftcms/cms/src/templates/users/_edit.html:206

But this is line 206 of templates/users/_edit.html in Craft 3.4.30:

https://github.com/craftcms/cms/blob/bd3820f19a0680c635a89c7f16805299964d97f2/src/templates/users/_edit.html#L206

Note there is no forms variable reference. Whereas there is on the same line in Craft 3.5.0:

https://github.com/craftcms/cms/blob/c6671af5af9e45f57ca9ab50d4b30b07282819d3/src/templates/users/_edit.html#L206

Either way, I’m not able to reproduce the error though. Can you try clearing out your storage/runtime/compiled_templates/ folder and see if that helps?

Yes, you're right, it is version 3.5.0, sorry about the typo. Unfortunately, clearing the storage/runtime/compiled_templates/ didn't work.

I wonder if the update just didn’t install properly for some reason. Can you try nuking your vendor folder, and then running composer install ?

Nuking the vendor folder didn't work. However, I did manage to narrow down the issue to this embed block: https://github.com/craftcms/cms/blob/develop/src/templates/users/_edit.html#L153. Commenting out that embed block allows the page to display normally.

Huh… that doesn’t really make any sense. There’s no forms reference inside that embed. If you restore the template file to the way it was, you get the error again?

Correct, uncommenting it causes the error to return. This doesn't make much sense to me either. Maybe my docker environment is broken. I'll try testing with a different php verison or something.

Yeah, not seeing this with PHP 7.2.32, so this must be some sort of bug with PHP 7.0.2.

For what its worth, I see this with craft 3.4.x on 7.0.2 too.

On 3.4.x the error points to:

https://github.com/craftcms/cms/blob/3.4/src/templates/users/_edit.html#L243

And I need to comment out the 2 following embed blocks to make the page display:

https://github.com/craftcms/cms/blob/3.4/src/templates/users/_edit.html#L161
https://github.com/craftcms/cms/blob/3.4/src/templates/users/_edit.html#L218

The errors all seem to revolve around embedding _includes/forms/field, but as you said, there doesn't seem to be any reference to forms inside that embed. I'll try to see if I can find which version of PHP fixed this between 7.0.2 and 7.2.32.

Appreciate you digging into it!

So, this affects PHP 7.0.1 and 7.0.2 (and presumably 7.0.0, but didn't bother to check). It works fine in PHP 7.0.3+. It seems that, for whatever reason, the {% embed %} statement is removing the macro import from the template scope/context. I confirmed this by leaving the {% embed %} statement in-place and just re-importing the macros after it.

I was able to repro with just twig. I've filed https://github.com/twigphp/Twig/issues/3385

Cool, guessing they won’t solve it because recent versions of Twig require PHP 7.1+ now. And it is likely due to a PHP bug, if 7.0.3+ is working, so likely not even something Twig could fix if they wanted to.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michaelhue picture michaelhue  Â·  3Comments

RitterKnightCreative picture RitterKnightCreative  Â·  3Comments

bitboxfw picture bitboxfw  Â·  3Comments

richhayler picture richhayler  Â·  3Comments

mattstein picture mattstein  Â·  3Comments