Search code examples
javascripthtmloctobercmsw3.js

W3.JS Display HTML Data {{variable}} in Octobercms Page or Partial


please help me with October CMS Code - Page or Partial, how to use them with W3.JS.

W3.JS Display HTML Data {{variable}} in Octobercms

{{ }} this transcription use OctoberCMS for your own data

But W3.JS Display HTML Data use the same transcription

https://www.w3schools.com/w3js/w3js_display.asp

<div id="id01">
{{firstName}} {{lastName}}
</div>

<script>
var myObject = {"firstName" : "John", "lastName" : "Doe"};
w3.displayObject("id01", myObject);
</script>

it doesn't work

thank you for your help

Vasek


Solution

  • It's very simple you just make it string so TWIG will treat it as a string and do not parse/interpolate it.

    ref: https://tutorialmeta.com/octobercms/october-cms-use-curly-brackets-twig-markup

    <div id="id01">
    {{ '{{firstName}} {{lastName}}' }}
    </div>
    
    <script>
    var myObject = {"firstName" : "John", "lastName" : "Doe"};
    w3.displayObject("id01", myObject);
    </script>
    

    {{ '{{firstName}} {{lastName}}' }} -> it will output {{firstName}} {{lastName}} in final markup

    if any doubt please comment