For my part, your example puts too much business logic into the view. "Is a user in this group" is valid as a templating question, but not valid for the template itself to solve.
So, for my part, I'd put a query method on your User entity, and leverage that in the view.
/* ... User Entity Class ... */
/**
* Does the User participate in the provided Group?
*
* @param Group $group The Group entity to check for participation
* @return boolean
*/
public function participatesInGroup( Group $group )
{
return in_array( $group->getId(), $this->participatedGroupIds() );
}
Then in your template you could either do
{% for group in groups %}
{% set vars = {'isMember': app.user.participatesInGroup(group)} %}
{% include 'GroupBundle:Default:minigroup.html.twig' with vars %}
{% endfor %}
Or skip the set
line altogether and let the template logic in minigroup.html.twig
make the query on its own.