Add Module after certain number of words in blog post?

MLerner
Member

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
3 Replies 3
Teun
Guide | Diamond Partner

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.

 

Did my answer solve your issue? Help the community by marking it as the solution.
Kevin-C
Recognized Expert | Partner

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.

Teun
Guide | Diamond Partner

Hi @MLerner ,

 

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

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