Hi,
I have successfully setup a TPL file (dynamic HTML page) that gets data from a lua file. However, I need to get data from a Mongo object and pass this data to the HTML file. The docs suggest I can use this method:
local obj, err = users:get(“id1234”) however I am not sure how to add a listener to be able to save the data from the results, and pass it into my data table.
Code is as follows:
local page = core.pages.new()
local drivers = core.data(“drivers”)
function getLat3 (evt )
if evt.error then
print(evt.error)
else
driverLat3 = evt.result.lattitude
end
return driverLat3
end
drivers:get({route=“someRoute”},getLat3)
local data = {
latitude = needDataFromMongoObject,
longitude = needDataFromMongoObject,
}
local body = page.template("/site/index.tpl", data)
page.response(body)
any ideas?
Thanks!