Skip to content
Advertisement

Can you read JSON into Laravel and turn into DOM element?

I have a JSON file with text. I want to print that out into a div and have an anchor tag inside it.

I have the JSON –

JavaScript

Inside my controller, I decode the JSON

JavaScript

Inside my view

JavaScript

At the moment the p tag would just echo the response as a string

A bunch of text here with a <a href=”#”>link</a>

How can turn this into html? Is that even a thing?

Advertisement

Answer

Basically Laravel does html entity encoding when you print something using {{ $text }}.

In order to not to encode HTML elements, you have to use

JavaScript

This can be also used for web page rendering as well for many other use case.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement