JavaScript Error because of rendered velocity line-break -


i use javascript-code in velocity-template , it's not working!

i read content template , want set js-variable, there line-breaks in content , following error:

syntaxerror: unterminated string literal

in rendered code there see error:

var exampletext = 'this first line  , second line.'; 

in original code written way:

    var exampletext = '$question.answer.data'; var regularpanels = new a.panel( {      bodycontent: exampletext,      collapsible: true,      collapsed: true,     headercontent: '$question.data' } ) .render('#regularpanels$counter$reserved-article-id.data$randomnamespace');    }); 

is there possibility ignore linebreak js-compilation, still show on complete rendered page?


okay, solved of escapetool velocity.

combined answer emiliocai it's following code works fine:

<div id="example-text" style="display:none;">    <p>$escapetool.java($question.answer.data).replace("\n","<br />")</p> </div>  <script type="text/javascript" charset="utf-8">  aui().ready('aui-panel', function(a) {   var exampletext = document.getelementbyid('example-text').innerhtml; var regularpanels = new a.panel( {      bodycontent: exampletext,      collapsible: true,      collapsed: true,     headercontent: '$question.data' } ) .render('#regularpanels$counter$reserved-article-id.data$randomnamespace');    });  </script> 

it might be, work without hidden <div>-tag, haven't tested yet.

so possible be:

var exampletext = '$escapetool.java($question.answer.data).replace("\n","<br />")'; 

tested -> works!

i'm sorry newlines not acceptable in javascript, not sure how template looks if cannot replace newlines \n or <br> can trick:

  • in template render contents coming database hidden div:

    <div id="example-text" style="display:none">$question.answer.data</div>

  • in javascript code read contents of div variable:

    var exampletext = document.getelementbyid('example-text').innerhtml;


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -