I have a category listing template where I'm having trouble passing in some variables.
top of the template I have this snippet where I'll set the channel and category field name based on the segment
{% set segment = craft.request.segment(1) %}
{# set channel based on segment_1 #}
{% if segment == "business-intel" %}
{% set channelName = "businessIntel" %}
{% set categoryName = "businessIntelCategories" %}
{% elseif segment == "foo" %}
{# do nothing #}
{% endif %}
{# end set channel #}
Then further down the template I have this:
{% include ('_includes/cat_sub_with_article') with { 'categoryName' : categoryName } %}
And then the included template looks like this:
{% for category, catEntries in entries | group('categoryName.first().title') %}
<h2>{{ category }}</h2>
{% set featuredThumb = {
mode: 'crop',
width: 370,
height: 168,
quality: 90,
position: 'top-center'
} %}
<div class="article-cards">
{% for entry in catEntries %}
<div class="article-card__wrapper">
<a href="{{ entry.url }}" class="article-card">
{% set image = entry.featuredImage.first() %}
<span class="article-card__image">
<img src="{{ image.url(featuredThumb) }}" />
</span>
<span class="article-card__text">
<span class="article-card__category">{{ entry.postDate.format('M d, Y') }}</span>
<h3 class="article-card__title">{{ entry.title }}</h3>
<p>{{ entry.featuredSummary }}</p>
<p><span class="link--green" href="{{ entry.url }}">Learn More</span></p>
</span>
</a>
</div>
{% endfor %}
</div><!-- /.article-cards -->
{% endfor %}
If I hardcode the category field name into line 1 of the above block everything works. However if I try to use the passed varialbe. I get this error, which I don't know how to fix:
Craft\EntryModel and its behaviors do not have a method or closure named "categoryName".