• Live group demo of Marketing Hub + Data Agent

    Standardize reporting, reduce manual work, and introduce AI without cleanup

    Join us on March 12
  • Ready to build your local HubSpot community?

    HUG leaders host events, spark connections, and create spaces where people learn and grow together.

    Become a HUG Leader

Get blog post ID (unique identifier) in for content in contents loop on Blog Listing Page

jmarcello
Participant

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?

0 Upvotes
1 Accepted solution
dennisedson
Solution
Community Manager
Community Manager

@jmarcello, try {{ content.id }} 


loop Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.
Learn More

View solution in original post

0 Upvotes
4 Replies 4
dennisedson
Solution
Community Manager
Community Manager

@jmarcello, try {{ content.id }} 


loop Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.
Learn More

0 Upvotes
jmarcello
Participant

Thanks...that worked. It would be helpful if that was documented, also some explanation as to what an alias is.

0 Upvotes
dennisedson
Community Manager
Community Manager

@jmarcello, i believe  there is a big push to get all the documentation sparkling clean. 

cc: @jausura

 

loop Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.
Learn More

0 Upvotes
jausura
HubSpot Employee
HubSpot Employee

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.

0 Upvotes