Gatsby: Render HTML tags from frontmatter

Created on 20 Feb 2018  路  2Comments  路  Source: gatsbyjs/gatsby

Description

Hello! New to using Gatsby and I'm trying to render HTML tags from a frontmatter field in a post template. I need a short paragraph of text with breaks in it separate to the main body of content from my Markdown file. I'm used to doing this with Hugo using it's safeHTML function. Is there a way I can do it in Gatsby?

I'm using the remark plugin to pull in my frontmatter fields. But it's just pulling in the text as a string, as expected.

Thanks!

Most helpful comment

You can use react's dangerouslySetInnerHTML (as a contrast to safeHTML i guess :) ):

<div dangerouslySetInnerHTML={{__html: post.frontmatter.fieldWithHtml }} />

All 2 comments

You can use react's dangerouslySetInnerHTML (as a contrast to safeHTML i guess :) ):

<div dangerouslySetInnerHTML={{__html: post.frontmatter.fieldWithHtml }} />

Doh. Of course that works! Thanks very much :)

Was this page helpful?
0 / 5 - 0 ratings