I'm trying to get the number of entries that have selected checkboxes.
This works successfully (where genreGames
is a checkbox field):
{{ games.genreGames('action').all()|length }}
Is there a way that I can do the same thing, except the field name is set dynamically? Like this:
{% set games = craft.entries().section('games') %}
{% set field = 'genreGames' %}
{{ games.field('action').all()|length }}
Obviously that won't work, but I need something similar.
The reason I need this is I'm building a solution for displaying the number of entries where a certain checkbox is checked. As you can see from the screenshot below, I want to set some parameters first and then use them below in my actual "template". It would also be nice to create a function to pass these variables in to and then output the template, but I do not know if this is possible in Twig.