I want to get data from rest API via javascript and show it in velocity temple.
In file example.js
AJS.toInit(function(){
var user = getCurrentUserName();
AJS.$(".....)....
...
}
function getCurrentUserName()
{
var baseUrl = AJS.params.baseURL;
var user;
AJS.$.ajax({
url: baseUrl+'/rest/gadget/1.0/currentUser',
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data
}
});
return user;
} In file example.vm
<div class="field-group">
<label for="multiselect">Multi select</label>
<select class="multi-select" size="4" multiple="multiple" id="multiselect" name="multiselect">
#foreach ($user in $user)
<option>$user.username</option>
#end
</select>
</div>
I want to get the user variable as $user in velocity template.
Could I do that?