Customize Blog Content Object

Hi,

I am trying to create a blog listing that has both a title and a subtitle. As far as I can see, the content object of the blog post has a title and a post body, author information, tags. Is there a way to add more fields that can then be accessed when iterating through the contents in the blog listing page as well? Also, is there any documentation that details all of the properties that are available in the content object?

Thank you in advance.

Hi @EJacobson,

yes - you can enhance the blog, template(s), hero, header, content what ever you like/need with so called custom modules.

Here are some resources for developing custom modules

Also I recommend you to create a free cms developer account and if you never worked with Hubl or developed anything in HubSpot → CMS for developers certification

My personal approach is always to create custom module and drop it in the template. If the user should not use it disable it for further useage - it will still work in the places you’re implementing it

important note: You can’t use modules inside modules

- - -

a basic custom listing module could look something like this

{% for content in contents %}
<figure class="card">
<img src="{{ content.featured_image }}" alt="{{ content.featured_image_alt_text }}" class="featuredImage">
<figcaption>
<h3>{{ content.name }}</h3>
<p class="summary">{{ content.post_body|striptags|truncatehtml(160,"...", true) }}
<a href="{{ content.absolute_url }}" class="readMore">read more</a>
</figcaption>
</figure>
{% endfor %}

But you don’t rely on the build-in loop “for content in contents” if you want more options or have a specific usecase you can use functions like blog_recent_posts to create your own custom listing. The module would look something like this:

{% set rec_posts = blog_recent_posts("default", 5) %}

{% for content in rec_posts %}
<figure class="card">
<img src="{{ content.featured_image }}" alt="{{ content.featured_image_alt_text }}" class="featuredImage">
<figcaption>
<h3>{{ content.name }}</h3>
<p class="summary">{{ content.post_body|striptags|truncatehtml(160,"...", true) }}
<a href="{{ content.absolute_url }}" class="readMore">read more</a>
</figcaption>
</figure>
{% endfor %}

what’s left is a bit of CSS to style it.

best,

Anton

Hi, I’m sorry if my question wasn’t clear. I know how to add custom modules to a template. My question is that I want to access a property of my custom blog post module, in my custom blog listing module. So that if I want to display something in my blog listing other than the featured image, name, post body, and absolute url, I should be able to do that. For instance, another piece of text, such as a subtitle, or a second image. Can I enable the user to set another property on the blog post, and then access that property on the blog listing?