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?

Arpita
  • 1,386
  • 1
  • 15
  • 35

1 Answers1

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) !!}

M.Elwan
  • 1,904
  • 1
  • 16
  • 21
  • Okay but when I write [[ json_encode($variableFromController) ]] it prints string `{"index":200}` and not `{"index":200}` how can I print the plane string without getting html entities relaced. – Arpita Apr 07 '17 at 10:13
  • I think it's nothing to do with laravel. it's html. in my case for testing I was using `
     //JSON content 
    ` but if you want other method I think `JSON.stringify` is what solves your case. look at: [this](http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript) or [this](http://stackoverflow.com/questions/14195530/how-to-display-raw-json-data-on-a-html-page)
    – M.Elwan Apr 07 '17 at 10:23