Add Module after certain number of words in blog post?

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”?

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.

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.

Hi @MLerner ,

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