CMS Development

MLerner
Member

Add Module after certain number of words in blog post?

SOLVE

I wanto have a certain module embedded in the text of my blog posts after, let's say 300 words. Is there a way to do this with Hubl to say "add module x after 400 words"?

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Add Module after certain number of words in blog post?

SOLVE

Hey @MLerner 

 

I would use javascript to solve this! This might help.

@Teun's solution is a solid one, but since the blog post is rich text, it's full of html tags and I think that'll give you issues.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

View solution in original post

3 Replies 3
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Add Module after certain number of words in blog post?

SOLVE

Hey @MLerner 

 

I would use javascript to solve this! This might help.

@Teun's solution is a solid one, but since the blog post is rich text, it's full of html tags and I think that'll give you issues.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Add Module after certain number of words in blog post?

SOLVE

Hi @MLerner ,

 

Gotta agree with @Kevin-C , above solution could give issues. Worth a shot if you do not want to use scripts.



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.


Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Add Module after certain number of words in blog post?

SOLVE

Hi @MLerner ,

 

You could try something like this:

 

{% set wordArray = module.content|split(' ') %}
{% set contentArray = wordArray.insert(400, 'set your HubL for the module here') %}
{% set content = contentArray|join(' ') %}

{{content}}

 

This is not tested, not sure if HubL will work if it is passed as a string, but could be worth a try. Change the 400 to any index you want.

 



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.