Display the HTML source code for a blog post via {{ article.content }} object

I’m trying to output the source code of a blog post for use in an affiliate program. In practice, an affiliate would read a blog article, and at the end would be able to copy its HTML to paste into their own site.

I was hopeful that the below would work, but it keeps the links and photos intact and just strips the fonts.

{{ article.content }}

| strip_html is almost what I wanted, but not quite as it removes all the HTML.

Is there an object filter that would convert {{ article.content }} to its HTML source?

Bonus: Is there a way I can create a button to copy that HTML to clipboard?

Hi IPedro,

Try this out and see if it gets you the result you’re after:

{{article.content | escape | replace: ‘<’, ‘<’ | replace: ‘>’, ‘>’}}

The escape filter escapes an HTML string into character keys, so

becomes

The replace functions should turn the character keys back into HTML for you

1 Like