Skip to content

Automatically add classes to blog post tags? #71

Discussion options

You must be logged in to vote

Other than using the replace twig filter, I don't think there is an easy way out of the box.

i.e.

{{ post.content_html | raw | replace({'<p>': '<p class="class1 class2">'}) }}

Thank you, this worked, albeit with a slight tweak. At first, it was outputting encoded HTML entities, so instead of <p> it would output &lt;p&gt;. But when I put the raw filter after replace, it worked! So the working solution looks like:

{{ post.content_html | replace({'<p>': '<p class="class1 class2">'}) | raw }}

which outputs the html.

Thanks so much!

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@OrigamiOrange
Comment options

Answer selected by OrigamiOrange
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants