Yeah, you can just use any of the Json API to convert your objects to Json, even if you don't have a Json Format defined you can use the library to do it more manually.
My code base has a similar requirement. We have a base_template.scala.html which takes several things like a body, jsMain - a .js file location for the page, and a headJs - a snippet of .js which is always put into the head.
So in the <head> of this template, we have:
<head>
..... // skipping some stuff
<script>
var Egraphs = Egraphs || {};
Egraphs.page = Egraphs.page || {};
Egraphs.page.jsMain = ["pages/base-template", "@jsMain"];
// skipping some more stuff
@headJs
</script>
@headHtml
</head>
This way we can pass .js as Html to the template and save some of the boilerplate writing on each page and just add to the Egraphs js object we defined in the base_template.
something like this would be defined in the template that calls our base_template.scala.html
@headJs = {
@if(signup) {
Egraphs.page.modalOn = true;
}
Egraphs.page.queryUrl = "@marketplaceRoute";
}
Then our jsMain can access that information off of Egraphs which will always be there.
Hope that helps in some way,
Cheers,
Myyk Seok