title: Laravel 5.2 Javascript call with blade parameter
body: <p>I have (currently) the following bit of code in my module.blade.php:</p>
  
  <pre><code>@section('scripts')
    &lt;script type="text/javascript"&gt;
        createMixin(['{{ $module }}']);
    &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p><strong>Explanation</strong>: </p>
  
  <ul>
  <li>$module is a variable holding a JSON packed with simple key => value, but also with key => object. It is loaded previously in a Controller and displayed in the blade.php.</li>
  </ul>
  
  <p>Example:</p>
  
  <p>{
       "title":"Title",
       "name":"dummy",
       "file":"dummy",
       "layout":"normal",
       "fields": [
         {
           "name": "bla"
         }
        ]
      }</p>
  
  <ul>
  <li>Function createMixin() would ideally generate a HTML out of Jade with the options inside $module (already existing).</li>
  </ul>
  
  <p><strong>Problem</strong> is: This does end in an error message: "htmlentities() expects parameter 1 to be string, array given"</p>
  
  <p><strong>Done so far:</strong> I have already tried several things:</p>
  
  <pre><code>@section('scripts')
    &lt;script type="text/javascript"&gt;
        var fields = $.parseJSON("{!! $module !!}");
        createMixin(fields);
    &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>@section('scripts')
    &lt;script type="text/javascript"&gt;
        createMixin("{!! JSON.parse($module) !!}");
    &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>@section('scripts')
    &lt;script type="text/javascript"&gt;
        createMixin("{!! json_encode($module) !!}");
    &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>@section('scripts')
    &lt;script type="text/javascript"&gt;
        $(this).createMixin("{{ $module }}");
    &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>I have had a look at several posts here (like <a href="https://stackoverflow.com/questions/34595446/laravel-javascript-passing-an-array-from-backend-to-a-array-in-javascript">this one</a>) and in other sources, they tell the people to use the php implode method or just a simple usage of "{!! !!}". But this all ends up in the same error message.</p>
  
  <p><strong>Question</strong>: What am I overlooking here? What am I doing wrong?</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>As requested my Javascript function:</p>
  
  <pre><code>//generate one jade mixin
  function createMixin(module) {
      //first load JSON...
      var json = $.parseJSON(loadJSON(module["file"]));
      //get options for mixin
      var options = json.fields;
      //detect jade file
      var jadepath = RESOURCES_DIR + "views/jade/" + json.file + "/template.jade";
  
      //check if file exists
      $.ajax({
          'url': jadepath,
          'type': 'HEAD',
          'error': function() {},
          'success': function () {
              var html = renderJade(options, jadepath);
              //save html into json
              json.html = html;
              var tmp = new Blob([html], { type: 'plain/text;charset=utf-8' });
  
          }
      });
  };
  </code></pre>