Get blog post ID (unique identifier) in for content in contents loop on Blog Listing Page
SOLVE
Hi:
Support suggest this variable to get the blog post ID (as a unique identifier):
{{ content_id }}
This works great when working in the Blog Post page template.
It does not seem to work when I add it to the for content in contents loop on my Blog Listings Page template.
For example, my loop might look like this:
<!-- Start Hubspot / Hubl loop here to display blog posts -->
<div class="row">
{% for content in contents %}
<div id="{{ content_id }}" class="post_box column one_third">
<article>
<div class="box">
<div class="inside">
<div class="thumbnail">
<a href="{{content.absolute_url}}">
<img width="480" height="270" src="{{ content.featured_image }}" class="flex" alt="{{ content.featured_image_alt_text }}">
</a>
</div>
</div>
</div>
</article>
</div>
{% endfor %}
</div>
<!-- End Hubspot / Hubl loop here to display blog posts -->
Ideally, if I was showing 6 blog posts on my blog post listings page, each one would have a unique identifier set as a CSS ID by getting and printing the value of {{ content_id}} as the code implies aboves.
How can I achieve this in a for loop on my blog listings page?
Get blog post ID (unique identifier) in for content in contents loop on Blog Listing Page
SOLVE
Thanks so much for the cc @dennisedson. We'll try to be more explicit about this when those docs get polished up, but you'll be happy to hear that I was writing about this exact topic in my script for the new CMS for Developers lesson covering blog markup.
@jmarcello I was honestly not sure how explicit to be about this potential point of confusion and your post here is a great gut check. So thanks to both of you and let me know if I can help clarify anything. To some degree this is just a fundamental aspect of looping through dictionaries with a for loop, but it doesn't help that a) we never really explicitly say that's what's happening and b) we use "content" and "contents". I wonder if you have any opinions about whether using "post in contents" in my examples would help clarify. Either way, thanks for the insight into your workflow.