title: How do you access a model attribute with javascript variable
body: <p>I'm adding an attribute to my <code>ModelAndView</code> in spring and after this i forwarding it to my thymeleaf view. </p>
  
  <p>In the view i have the following code:</p>
  
  <pre><code>&lt;script th:inline="javascript"&gt;
          /*&lt;![CDATA[*/
              var applicationName = /*[[${T(com.sample.constants.ApplicationConstants).MODEL_ATTR_COLLECTED_VALUES}]]*/ "Test";
              var collectedValueJson = [[${collectedValues}]];
              console.log(collectedUserJson);
          /*]]&gt;*/
  &lt;/script&gt;
  </code></pre>
  
  <p>Result from this is </p>
  
  <pre><code>var applicationName = 'collectedValues';
  var collectedUserJson = '[{\"givenname\":\"Muster\",\"surname\":\"Peter\"}]';
  </code></pre>
  
  <p>That's fine. Now my wish for this is, that i can take the <code>var application</code> and access with this variable the modelattribute, but that's not working.</p>
  
  <p>Result is this:</p>
  
  <pre><code>var tmp2 = ${applicationName};
  </code></pre>
  
  <p>An other try was, that i have access to the modelattribute with the syntax  <code>/*[[ ]]*/</code> from the first try:</p>
  
  <pre><code>var applicationName = ${/*[[${T(com.sample.constants.ApplicationConstants).MODEL_ATTR_COLLECTED_VALUES}]]*/};
  </code></pre>
  
  <p>But result will be:</p>
  
  <pre><code>var tmp = ${'collectedValues'
  </code></pre>
  
  <p>i have no idea what can i try.</p>
  
  <p>Any other suggestions?</p>
  
  <p>Thank's in advance.</p>