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)

Most upvoted comments

I’m against this change because in my mind has has a different meaning. has often relates to an inclusion check for collections. Using it as a substitute of is may confuse beginners.

So, has is indeed not a synonym for is. What we could do is add support for has but only for specific tests. A test would basically be able to choose if it works with is or has, defaulting to is for BC reasons (and because it makes more sense most of the time).

Tests triggered by has should be separated from tests triggered by is to avoid weird tests such as foo has divisible by (3).