I'm using Stash to capture a list of articles. I'm trying to keep my viewModel separate from my view markup.
For each article, I'm capturing a nested list of categories.
In the view, I want to output comma-separated categories. I was under the impression that I could use backspace="x" on a get_list, but it doesn't seem to work. I am I going about this incorrectly?
I suppose I could use an if/else with 'count' and 'total_results' to remove the final comma and space, but would also like to know if backspace can work.
Set article list
{!-- Articles --}
{exp:stash:set_list name="articles" parse_tags="yes" parse_depth="2"}
{exp:channel:entries
channel="news"
dynamic="no"
orderby="sticky|entry_date"
sort="desc|desc"
sort_type="numeric|numeric"
disable="member_data|category_fields"
{triggers:entries}
}
{stash:id}{entry_id}{/stash:id}
{stash:sticky}{sticky}{/stash:sticky}
{stash:title}{title}{/stash:title}
{stash:summary}{article_summary}{/stash:summary}
{stash:date}{entry_date}{/stash:date}
{stash:url}{page_url}{/stash:url}
{stash:image}{article_featured_image}{/stash:image}
{exp:stash:set_list:nested name="this_article_categories" parse_tags="yes" context="{entry_id}"}
{categories}
{stash:category_name}{category_name}{/stash:category_name}
{stash:category_url_title}{category_url_title}{/stash:category_url_title}
{/categories}
{/exp:stash:set_list:nested}
{/exp:channel:entries}
{/exp:stash:set_list}
Get Articles (See the get_list:nested name="this_article_categories" in the code below.)
{!-- Get Articles --}
{exp:stash:get_list name="articles" prefix="news" paginate="bottom" limit="15"}
<article>
<header>
<div class="meta">
{news:date format="%M %j, %Y"} in {exp:stash:get_list:nested name="this_article_categories" backspace="2" context="{news:id}"}
<a href="/news-events/news/category/{category_url_title}">{category_name}</a>,
{/exp:stash:get_list:nested}
</div>
<h1 class="gamma"><a href="{news:url}">{news:title}</a></h1>
</header>
<div class="article-body">
{news:summary}
</div>
<p class="read-more"><a href="{news:url}">Continue reading <i class="ss-gizmo ss-right"></i></a></p>
</article>
<hr>
{/exp:stash:get_list}