CMS Development

david_eic
Teilnehmer/-in | Gold Partner
Teilnehmer/-in | Gold Partner

Display blog post snippet

lösung

Hi,

 

I'm currently building a blog template that outputs a couple of lines preview text on the listing page.

 

At the minute I'm using the {{ content.post_list_content }} hubl tag to display the preview text but it pulls through html like <a> tags and <video> elements which should be stripped out.

 

Does anyone know the best way to pull the preview text into a blog template as text and strip out the html?

 

Thanks for your help!

David

1 Akzeptierte Lösung
JasonRosa
Lösung
HubSpot Employee
HubSpot Employee

Display blog post snippet

lösung

Hey @david_eic you can accomplish this by using the striptags HubL filter which is documented here. Your code would look something like this: 

 

<p>{{ content.post_list_content|striptags }}</p>

 

Let me know if you have any questions about this!

Lösung in ursprünglichem Beitrag anzeigen

5 Antworten
Techclaro
Teilnehmer/-in

Display blog post snippet

lösung

striptags

Strip SGML/XML tags and replace adjacent whitespace by one space. This filter can be used to remove any HTML tags from a variable.

 

safe

Mark the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped.

 
{{ topic_post.post_list_content|safe|striptags }}

 

 

0 Upvotes
madraxsam
Teilnehmer/-in

Display blog post snippet

lösung

I'm having a similar issue on my blog listing page (https://blog.madrax.com/blog) with HubSpot Videos. Where in the preview text it's bringing in the video code:

{% video_player "embed_player" overrideable=False, type='scriptV4', hide_playlist=True, viral_sharing=False, embed_button=False, autoplay=False, hidden_controls=False, loop=False,...

 

This is what is in my blog listing code:

<p>{{ content.post_list_content|safe|truncatehtml(190 )|striptags }}</p>

 

Any idea how to keep that video code from showing up? 

0 Upvotes
madraxsam
Teilnehmer/-in

Display blog post snippet

lösung

Figured it out, the striptags needs to be before the truncatehtml in the code. 

BManandhar
Mitglied

Display blog post snippet

lösung

Hi there, how do I pull all the tags without strip it one?

0 Upvotes
JasonRosa
Lösung
HubSpot Employee
HubSpot Employee

Display blog post snippet

lösung

Hey @david_eic you can accomplish this by using the striptags HubL filter which is documented here. Your code would look something like this: 

 

<p>{{ content.post_list_content|striptags }}</p>

 

Let me know if you have any questions about this!