My Aim: Learn the limitations (if any) on parameters that I can send from the controller to view. Right now, I'm checking if I can send any Twirl's keyword (e.g., @, @for, etc.) from the controller function to the view, and then reload a part of the page using JS.
We can pass a raw HTML to the view while using as(HTML)
in a controller function. However is it possible to send a block of scala.html
type code with all their syntax sugar from the controllers' function to views' related JS function; so that it can show it in the related div? For example how/can I can pass the following:
<p style="padding:1rem;"> @for(i <- items){<h2>i.name</h2} </p>
If I wrap the above in a controller function:
Ok(<p style="padding:1rem;"> @for(i <- items){<h2>i.name</h2} </p>).as(HTML)
Rightfully so, I will get the following error; as the code is not pure HTML:
So Is there a way? or all the template related engine's keywords can not be send from the controller to the view?; and only need to be used on the views' files.