Blog categories shows erroneously

Karim Kendjouh asked on May 1, 2017 22:31


I am currently using a transformation in a Repeater to display blog articles. However, I am having issues with Categories.

The category shows well inside the article (using CurrentDocument.Categories), however I can't get the equivalent to work in a transformation with the data returned.

I have currently:

<div class="blog-item-container">
  <div class="blog-item">
    <div class="blog-category">{% Documents[DocumentID].Categories.FirstItem.CategoryDisplayName %}</div>
    {% if (DocumentPageImage != null) { %}<div class="img-wrapper"><a href="{% GetDocumentUrl() %}"><img class="blog-img" src="~/CMSPages/GetFile.aspx?guid={% DocumentPageImage %}" alt=""></a></div>{% } #%}
    <h4><a href="{% GetDocumentUrl() %}">{% DocumentPageTitle %}</a></h4>
    <p>{% DocumentPageDescription %}</p>

The problem line :

{% Documents[DocumentID].Categories.FirstItem.CategoryDisplayName %}

However, even though it returns a category for half the articles, it always return the same category and it is even the wrong one. I can filter by categories and everything, but my blog page shows the wrong categories in the listing. How should I go about to display categories in a repeater transformation? Is there seriously no built-in method to do it in a macro? All my articles only have 1 selected category. I just need to show the "first one".



Correct Answer

Rui Wang answered on May 2, 2017 16:44

Try this {% Documents[NodeAliasPath].Categories.FirstItem.CategoryDisplayName %}

0 votesVote for this answer Unmark Correct answer

Recent Answers

Karim Kendjouh answered on May 2, 2017 16:52

Thanks Rui! This works perfectly! I didn't think about the NodeAliasPath when I was looking for alternative options. I'll know better for the next time.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.