Passing a variable to an include
You set the variable that your are passing in to your include to a string. And in your include you try to access it like an object.

The variable which you’re passing in to your include is set to a string 'businessIntelCategories'. And in your include you try access a object property dynamically using that string which doesn’t work.

Use this code instead.

{% set entriesGrouped = entries|group('{ object[categoryName].first().title }') %}


Here’s an attempt to explain the syntax.

First you should have a look at the Craft documentation for Dynamic Entry Titles. You see that you can dynamically generate titles with a normal Twig template {{ object.property }} or a special shortcut syntax {property}.

The group filter uses the same internal functionality to render the string that you pass in as a filter argument group('my twig template string'). The syntax has to be a bit different though, because group already adds one pair of curly braces for you.

So usually you echo the title property like so

{{ object.title }}


and in the context of the group filter you can do both of the following.

{% set entriesGrouped = entries|group('title') %}

{% set entriesGrouped = entries|group('{ object.title }') %}


The first syntax, which uses the shortcut syntax, is documented and fine for most cases. But you can’t use it if you need to do something a bit more advanced, like using a ternary operator or in your case access the object object differently.

So to wrap this up, the syntax for group('{ object[categoryName].first().title }') is confusing. But what it does is to render the following Twig code for each element of your array of entries (each entry is passed in as the variable object).

{{ object[categoryName].first().title }}


If you don’t like the object['propertyName'] syntax, you can use the attribute function instead.

{{ attribute(object, categoryName).first().title }}