Twig icon indicating copy to clipboard operation
Twig copied to clipboard

'ignore missing' does not ignore missing templates

Open derekalmond opened this issue 5 years ago • 5 comments

This appears like it might well be a Twig bug, on my local, using the version on my branch (v1.38.4 ) adding a made up template to the homepage:

{% set x = 'bad' %} {% embed x ~ 'ger.twig' ignore missing %} {% endembed %}

Does not error, removing 'ignore missing' causes it to error…

Upgrading twig/twig (v1.38.4 => v1.42.1)

At which point the ignore missing directive appears to no longer work and the above test fails

Twig\Error\LoaderError thrown with message "Unable to find template

derekalmond avatar Jul 09 '19 11:07 derekalmond

I've tried several times to fix it but it's really complicated as we don't have enough context when we need it.

fabpot avatar Aug 07 '19 14:08 fabpot

Just tried updating from twig 2.6 to 2.12 and "ignore missing" is not working here either. I reverted to 2.6. Is this going to be fixed?

kitsguru avatar Dec 04 '19 23:12 kitsguru

@kitsguru It will be fixed eventually, but any help would be more than welcome.

fabpot avatar Dec 05 '19 05:12 fabpot

I just tried V3.0.0 and it is broken here as well. I have been looking through the code and can't find a test for "ignore missing". You mention something about not having enough context but it would seem to me that the only context needed is if the attribute is present. If present don't throw an exception.

Am I missing something here? If you could point me in the right direction, I will keep on looking.

As a workaround I am modifying my app and adding a folder called 'missing', adding an array for the embed file instead of a single file and placing a dummy file in 'missing'.

kitsguru avatar Dec 22 '19 17:12 kitsguru

This error still happens nowadays. I'm looking into the version change this happened.

EDIT:

  • This is first narrow version change this bug first occurs: v2.14.8 => v2.14.9
  • The full diff between those 2 versions: https://github.com/twigphp/Twig/compare/v2.14.8...v2.14.9
  • So this is the breaking commit: https://github.com/twigphp/Twig/commit/695423e14e212930099838102c23dc8ee8ac1558

TomasVotruba avatar Oct 31 '22 23:10 TomasVotruba