Volt template is acting strange - comments within JS is commenting out the complete function when rendering

Hi,

When I add any comments in my js using volt, the next block of js code is also commented out and I get javascript errors.

So for example the following .volt file

<html>

<head>
  <script>
    //this function alert to the screen hello world
    function hello() {
      alert("hello world!");
    }
  </script>
</head>

<body>
  <button onclick="hello();">Click Me</button>
</body>

</html>

Is rendered as:

<html>

<head>
  <script>
    //this function alert to the screen hello world
   // function hello() {
   //   alert("hello world!");
   // }
  </script>
</head>

<body>
  <button onclick="hello();">Click Me</button>
</body>

</html>

Any tips on how to resolve would be appreciated. (As a workaround I can remove the comments for now, but when I integrate any 3rd party plugins eg. paypal / stripe, I am going to have problems).

Thanks

Put js code into file?



2.1k

Hi,

I have tried that peviously and gives samwe result.

If by chance you used Devtools to start a project, the public/index.php sometimes has some "compression" techniques on the getContent() output...



2.1k

@Trent thanks for pointing me in the right direction,

echo str_replace(["\n","\r","\t"], '', $application->handle()->getContent());

the \n is causing the problem, what would be the impact of changing the code to just :

echo $application->handle()->getContent();

Thanks

nothing will impact.. for some reason that was added to condense the html output, but any JS on the page breaks.