Twig: Use "has" as trigger for tests
I have a test that I can use as follows:
{% if app.user is user_that_has_more_than_one_partner %}
This is verbose, and I was wondering if it might not make more sense to create a has keyword that triggers a test like is does. That way, we could use:
{% if app.user has more_than_one_partner %}
Since has typically returns a boolean response, I would consider this useful in many more instances.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 26
- Comments: 30 (24 by maintainers)
I’m against this change because in my mind
hashas a different meaning.hasoften relates to an inclusion check for collections. Using it as a substitute ofismay confuse beginners.So,
hasis indeed not a synonym foris. What we could do is add support forhasbut only for specific tests. A test would basically be able to choose if it works withisorhas, defaulting toisfor BC reasons (and because it makes more sense most of the time).Tests triggered by
hasshould be separated from tests triggered byisto avoid weird tests such asfoo has divisible by (3).