I am sending a variable in a modelmap from java controller to a view like this :
@RequestMapping(value = "/someAction", method = RequestMethod.GET)
public String search(ModelMap model) {
model.addAttribute("myVariable",true);
return "myView"; //returns the view
}
Now i have this view file "myView.html" where i've used jsrender and that has a data and i iterate it like given below.Also i need to use the "myVariable" inside that iteration like this :
<script id="iterData" type="text/x-jsrender">
{^{for #data}}
{{if Name != '-'}}
{{if Age =='20'}}
{{if myVariable??}} //This part doesnt work.I wonder how to use it here
//Some codes
{{/if}}
{{/if}}
{{/if}}
{{/for}}
</script>
Can anyone help me how i could use the "myvariable" inside the jsrender iteration??
I'm not sure about your use of
{{for #data}}
- hence my question in a comment.But one way of passing in variables to nested template contexts is as by passing in a template variable from the outer context to the inner contexts:
For example, if
myVariable
is a property on any outer context, you can write: