echo and blade escapes strings

Posted 2 years ago by eddieace

I have a codeblock that looks like this.

My problem is that everything after the var _globalObj row becomes green (the whole file)

    <script>
        var _globalObj = '<?php echo json_encode(array('_token'=> csrf_token())) ?>';
        var enableUrl = '{{url("admin/positions/enable-editor/" . $position->id)}}';
    </script>

I would like to have it something like this

    <script>
        var _globalObj = '{{ json_encode(array('_token'=> csrf_token())) }}';
        var enableUrl = '{{url("admin/positions/enable-editor/" . $position->id)}}';
    </script>

But for some reason blade escapes alot some json stuff like back slashes etc.

Any clues on how to solve this?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.