A clever way to embed user data in content from Prismic?

I am curious to know if the community has any suggestions of clever ways to work out an implementation to embed user data into the Prismic content that gets rendered to the page. For example, your marketing team wants to build a page with content that can be tailored to each user - let's say it is a page which displays usage statistics for each user. In Prismic, the marketing team uses a Rich Text field with something like the following:

"Hello, ${userName}! Welcome to our new splash page!"

Is there a clever way to render the Prismic content in such a way that it is adaptive to user data stored in the application's state?

I have thought about parsing the string that gets received in the JSON object from Prismic and then mutating the string but I am curious to know if there are people who have tried something else?

Thanks!

Hi Conrad,

What I think might work in your case is to have a look at the HTML Serializer, this is what is used to turn the Prismic Rich Text data in to HTML in your front end application.

You could import the application state in to this file and using some sort of variable declaration like you suggested above, you could parse the object and add the user data. I'm guessing this is what you were suggesting. Other than that I can't think of any other way to do this.

Let me know what you think.

Thanks.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.