givanz / VvvebJs

Drag and drop page builder library written in vanilla javascript without dependencies or build tools.
https://www.vvveb.com/vvvebjs/editor.html
Apache License 2.0
7.07k stars 1.62k forks source link

Uncaught SyntaxError: Invalid or unexpected token #240

Open pepijndik opened 2 years ago

pepijndik commented 2 years ago

I am getting this strange error when fetching HTML from a variable

   Vvveb.Builder.init('about:blank', function () {
            Vvveb.Gui.init();
            Vvveb.Builder.setHtml('{!! $html !!}');

        });

The {!! $html !!} is a PHP blade variable, When looking at the inspector it will throw because the next lines are not inside a string? I don't like to do a for each loop to add for each line quotes around it?

Hope there is a better way to do this

givanz commented 2 years ago

Hi

I tried your code and {!! $html !!} is properly displayed in the page.

If you need {!! $html !!} to be processed by php before adding it to the page you will need first to send it to the server to be processed by php (blade).

You can do this with ajax and then set the content with something like:

$.get('/process-blade.php',  {bladeCode:'{!! $html !!}'}, function (data, textStatus, jqXHR) {
  Vvveb.Builder.setHtml(data);
});