CMS Development

DEsteva
Contributor

Getting blog listing data from a module

SOLVE

Hello guys! How are you?

 

I'm working on getting data from a Blog Listing Module to a Webpage, actually the module if working smoothly on the Blog Templates but i can't make it work on Website Pages. On the Blogs its works like you can see on the attatched photo. 

 

Screenshot 2024-09-24 at 15.58.46.jpg

 

But on the website pages but it doesn't show. As you can see in the next photo. It should be available on the section marked with a red rectangle. Screenshot 2024-09-24 at 16.03.30.png

 

The layout that is not being viewed is the next one: 

<section class="hs-blog-post-listing hs-blog-post-listing--{{ layout }}">
  {% for content in contents %}

    {# Blog listing article #}

    <article
      class="hs-blog-post-listing__post hs-blog-post-listing__post--{{ layout }} {{ "hs-blog-post-listing__post--{{ columns }}" if has_columns }}"
      {% if has_full_image and content.featured_image %}
        style="background-image: url({{ content.featured_image }});"
      {% endif %}
      aria-label="{{ module.default_text.full_blog_post_summary_text }}"
    >

      {# Adds a wrapper for an overlay if full image is enabled #}

      {% if has_full_image and content.featured_image %}
        <div class="hs-blog-post-listing__post-inner-wrapper">
      {% endif %}

        {# Post image #}

        {% if not has_alternate_image or loop.index is not divisibleby 2 %}
          {{ post_image("left") }}
        {% elif has_alternate_image and loop.index is divisibleby 2 %}
          {{ post_image("right") }}
        {% endif %}

        {# Article content #}

        {{ post_content() }}

      {# Adds a wrapper for an overlay if full image is enabled #}

      {% if has_full_image and content.featured_image %}
        </div>
      {% endif %}

    </article>
  {% endfor %}

</section>

 

Thanks guys!

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Getting blog listing data from a module

SOLVE

Hi @DEsteva ,

 

The `contents` variable is only available on the blog listing page, so you can't loop through it on a website page.

In that case, you can use the blog_recent_posts function on a website page to retrieve your blog posts. You can pass 'default' as the first parameter to retrieve the primary blog or pass the ID of a specific blog.

 

You could try updating your code to something like this:

 

{% set posts = contents ? contents : blog_recent_posts("default", 200) %}

<section class="hs-blog-post-listing hs-blog-post-listing--{{ layout }}">
  {% for content in posts %}

    {# Blog listing article #}

    <article
      class="hs-blog-post-listing__post hs-blog-post-listing__post--{{ layout }} {{ "hs-blog-post-listing__post--{{ columns }}" if has_columns }}"
      {% if has_full_image and content.featured_image %}
        style="background-image: url({{ content.featured_image }});"
      {% endif %}
      aria-label="{{ module.default_text.full_blog_post_summary_text }}"
    >

      {# Adds a wrapper for an overlay if full image is enabled #}

      {% if has_full_image and content.featured_image %}
        <div class="hs-blog-post-listing__post-inner-wrapper">
      {% endif %}

        {# Post image #}

        {% if not has_alternate_image or loop.index is not divisibleby 2 %}
          {{ post_image("left") }}
        {% elif has_alternate_image and loop.index is divisibleby 2 %}
          {{ post_image("right") }}
        {% endif %}

        {# Article content #}

        {{ post_content() }}

      {# Adds a wrapper for an overlay if full image is enabled #}

      {% if has_full_image and content.featured_image %}
        </div>
      {% endif %}

    </article>
  {% endfor %}

</section>

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

1 Reply 1
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Getting blog listing data from a module

SOLVE

Hi @DEsteva ,

 

The `contents` variable is only available on the blog listing page, so you can't loop through it on a website page.

In that case, you can use the blog_recent_posts function on a website page to retrieve your blog posts. You can pass 'default' as the first parameter to retrieve the primary blog or pass the ID of a specific blog.

 

You could try updating your code to something like this:

 

{% set posts = contents ? contents : blog_recent_posts("default", 200) %}

<section class="hs-blog-post-listing hs-blog-post-listing--{{ layout }}">
  {% for content in posts %}

    {# Blog listing article #}

    <article
      class="hs-blog-post-listing__post hs-blog-post-listing__post--{{ layout }} {{ "hs-blog-post-listing__post--{{ columns }}" if has_columns }}"
      {% if has_full_image and content.featured_image %}
        style="background-image: url({{ content.featured_image }});"
      {% endif %}
      aria-label="{{ module.default_text.full_blog_post_summary_text }}"
    >

      {# Adds a wrapper for an overlay if full image is enabled #}

      {% if has_full_image and content.featured_image %}
        <div class="hs-blog-post-listing__post-inner-wrapper">
      {% endif %}

        {# Post image #}

        {% if not has_alternate_image or loop.index is not divisibleby 2 %}
          {{ post_image("left") }}
        {% elif has_alternate_image and loop.index is divisibleby 2 %}
          {{ post_image("right") }}
        {% endif %}

        {# Article content #}

        {{ post_content() }}

      {# Adds a wrapper for an overlay if full image is enabled #}

      {% if has_full_image and content.featured_image %}
        </div>
      {% endif %}

    </article>
  {% endfor %}

</section>

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.