Problem/Motivation
The cheat sheat says
This is an opposite of core without filter.
This is incorrect and misleading, the with function (not using the phrase "filter" class here to avoid confusion) does something with a render array key, but it does not filter (remove, reduce,...) something.
Proposed resolution
Change documentation to
This filter allows to set a value in a render array.
API changes
Maybe change the function name in the next major version? It behaves like a setter, but the TwigFilter name set is already used by Components! module. Something like set_by_key?
Comments
Comment #2
hudriComment #3
hudriComment #4
chi commentedMany other Twig Tweak filters are also not filters. And Drupal core has such examples as well. Furthermore Twig itself has filters that don't filter anything. That's a historical naming convention that we can't change.
https://github.com/twigphp/Twig/issues/3298
Comment #5
hudriMy "filter" comment was meant in regard to the current description (the opposite of core's
without), becausewithoutactually does filter a render array. I can't see the reason whywith(setter) should be the opposite ofwithout(filter)Comment #6
chi commentedwithoutremoves propertieswithadds propertiesIsn't this what "opposite" term means?
Comment #7
hudriOK, now I got the naming.
In my mental model,
withoutis a filter by disallow list, so reading the description I thoughtwithis a filter by safe list, and used it likecontent|with(computedListOfAllowedFieldnames). This did not work and resulted into the creation of this issue.I'd suggest extending the description in the cheat sheat to
Comment #9
hudriComment #10
shyam_bhatt@hudri I have checked the "MR !39", documentation updated on the "cheat-sheet.md" file.
Before:

After:

+ Moving to RTBC
Comment #11
chi commented@Shyam_Bhatt no need to make screenshots for code. It only proves that you correctly deployed the Git branch to your localhost.
The change is visible here.
https://git.drupalcode.org/issue/twig_tweak-3399652/-/blob/3399652-with-...
Thank you.