CMS Development

jonflynnh2o
Participant | Partner
Participant | Partner

Get page HTML via hubl

SOLVE

I'm trying to implement a read time feature where read time is generated via hubl for the current blog post. Was following this: https://designers.hubspot.com/code-gallery/entry/founders/ericsalvi-Add-Reading-Minutes-to-Blog-Post...

 

 However, currently "content.post_body" is returning nothing as we are using custom modules to populate the blog post and not the standard Blog Content/Rich Text module. Is there a way I can get the HTML of the whole page, or access the HTML in the other modules to then calculate the read time?

0 Upvotes
1 Accepted solution
Anton
Solution
Thought Leader

Get page HTML via hubl

SOLVE

Hi @jonflynnh2o,

 

I would try to concatenate all of the "rich-text" values into a single hubl like

 

{% set total_readtime = module.rich_text_1 ~ module.rich_text_2 ...%}

 

and then modify the read time code to this:

 

{% set initialPostWords = total_readtime|striptags|wordcount %}
{% set calculatedPostWords = (initialPostWords/100) * 100 %}
{% set finishedPostWords = calculatedPostWords|divide(300)|round(2) %}
{% set number = finishedPostWords|round %}
{% if number < 1 %}
 
{% else %}
  {{ finishedPostWords|round }} minute read
{% endif %}

 

 

Just a quick tipp: you should use the default "content.post_body" option somewhere in the post. Maybe for the "intro". Otherwise you'll need to rewrite module like "latest posts" or similar (all modules which displays some kind of blog information preview)

 

best, 

Anton

Anton Bujanowski Signature

View solution in original post

2 Replies 2
Anton
Solution
Thought Leader

Get page HTML via hubl

SOLVE

Hi @jonflynnh2o,

 

I would try to concatenate all of the "rich-text" values into a single hubl like

 

{% set total_readtime = module.rich_text_1 ~ module.rich_text_2 ...%}

 

and then modify the read time code to this:

 

{% set initialPostWords = total_readtime|striptags|wordcount %}
{% set calculatedPostWords = (initialPostWords/100) * 100 %}
{% set finishedPostWords = calculatedPostWords|divide(300)|round(2) %}
{% set number = finishedPostWords|round %}
{% if number < 1 %}
 
{% else %}
  {{ finishedPostWords|round }} minute read
{% endif %}

 

 

Just a quick tipp: you should use the default "content.post_body" option somewhere in the post. Maybe for the "intro". Otherwise you'll need to rewrite module like "latest posts" or similar (all modules which displays some kind of blog information preview)

 

best, 

Anton

Anton Bujanowski Signature
dennisedson
HubSpot Product Team
HubSpot Product Team

Get page HTML via hubl

SOLVE

Hey @jonflynnh2o !

Might be worth looking at the developer info (in the sprocket dropdown)

You should get a JSON output of all of the data on the page.

@Anton or @alyssamwilie could probably help out more 😉

0 Upvotes