0

Hi i need convert html string and push to js var.

I convert it for JS in TWIG

$loadContent = '<html><.....' 


data-template-content="'{{ loadContent|escape('js')|raw }}'" 

get somethink like that in Javascript/jquery $('body').attr('data-template-content')

title\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0021\u002D\u002D\u005Bif\u0020\u0021mso\u005D\u003E\u003C\u0021\u002D\u002D\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Clink\u0020href\u003D\u0022https\u003A\/\/fonts.googleapis.com\/css\u003Ffamily\u003DLato\u0022\u0020rel\u003D\u0022stylesheet\u0022\u0020type\u003D\u0022text\/css\u0022\/\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\u0021\u002D\u002D\u003C\u0021\u005Bendif\

How restore orginal content with js ?

i try

unescape($('body').attr('data-template-content'))

or

JSON.parse($('body').attr('data-template-content'))

or

decodeHtmlEntities(value){
        let txt = document.createElement("textarea");
        txt.innerHTML = value;
        return txt.value;
    }

not work ..

"Your question has been identified as a possible duplicate of another question" - (no this is other question) - how to escape in twig - this i know but how get original in JS this is question. I twig doc is no info about restore in JS,

use json_encode|raw ???

im in Javascript , i encode in twig and want get orginal in Javascript

Developer
  • 2,731
  • 2
  • 41
  • 71

0 Answers0