title: How to pass a value directly from a controller to a javascript file in Grails
body: <p>Would like to pass directly from the controller to a JavaScript file. </p>
  
  <p>TestControler.groovy</p>
  
  <pre><code>def list() {
      render (view: "list", model:[theId: theId])
  }
  </code></pre>
  
  <p>Test.js</p>
  
  <pre><code>function test() {
     // do smth with theId
  }
  </code></pre>
  
  <p>Found solution have the rendered gsp in the middle, i.e. <a href="https://stackoverflow.com/questions/25702043/passing-values-from-a-controller-to-a-gsp-to-a-javascript-function">this one</a>, but I would like to know if there is a way to avoid that including using hidden fields or having in the gsp file a javascript code snippet such as:</p>
  
  <pre><code>&lt;g:javascript&gt;
     function test(${theId}) {
         // do smth with theId
     }
  &lt;/g:javascript&gt;
  </code></pre>