0

Hi I am new to templates and laravel.

I have changed the laravel delimiters to [[]] and [[[]]] using

Blade::setContentTags("[[", "]]");
Blade::setEscapedContentTags("[[[", "]]]");

Now I want to pass the json to a javascript variable like

var somevariable = [[json_encode($variableFromController)]];

but this converts the json string to html entities like

{"index":200}

I searched and Found that {{!!json_encode($variableFromController)!!}} should work but doing this in my system like [[!!json_encode($variableFromController)!!]] does not makes any impact.

I Know I can do something like <?php echo json_encode($variableFromController) ?> but this is the last thing I want to try. is there any laravel specific thing I can do?

1 Answer 1

1

at first Blade::setContentTags("[[", "]]"); means that replace {!! with [[. and Blade::setEscapedContentTags("[[[", "]]]"); is replacing {{ with [[[.

so for your condition [[ json_encode($variableFromController) ]] is the equivalent for {!! json_encode($variableFromController) !!}

Sign up to request clarification or add additional context in comments.

2 Comments

Okay but when I write [[ json_encode($variableFromController) ]] it prints string {&quot;index&quot;:200} and not {"index":200} how can I print the plane string without getting html entities relaced.
I think it's nothing to do with laravel. it's html. in my case for testing I was using <pre> //JSON content </pre> but if you want other method I think JSON.stringify is what solves your case. look at: this or this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.