Accessing data from template
This page summarizes all the concepts needed to access data from a template
Main
The @Model decorator
@Model()Usage
./src/main/resources/templates/my-template.html
<h2>Hello <%= data.name %> <%= data.lastname %></h2>
<small>Your current address is: <%= data.address.city %>, <%= data.address.state %>, <%= data.address.country %>. </small>
import { Controller, GET, Render, Model, ViewModel, MandarineCore } from "https://deno.land/x/mandarinets/mod.ts";
@Controller()
export class MyController {
@GET('/path-template')
@Render('my-template.html')
public httpHandler(@Model() model: ViewModel) {
model.setAttribute("data", {
name: "Andres",
lastname: "Pirela",
address: {
city: "New york",
state: "NY",
country: "United States"
}
});
// returning ViewModel object.
return model;
}
@GET('/manual-template')
@Render(`<h2><%= name %></h2>`, { manual: true })
public httpHandler2() {
return {
name: "Andres"
};
}
}
new MandarineCore().MVC().run();

Last updated