> For the complete documentation index, see [llms.txt](https://mandarineframework.gitbook.io/mandarine-ts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mandarineframework.gitbook.io/mandarine-ts/v1.0.1/mandarine-mvc/template-engine/accessing-data-from-template.md).

# Accessing data from template

This page summarizes all the concepts needed to access data from a template

## Main

Mandarine's engine allows you to interact and make your templates access data located in your application's back-end. For this, your [HTTP Handler](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-mvc/controllers/http-handlers) decorated with [`@Render`](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-mvc/template-engine/render-decorator) must return an object. This object will then be accessible from the template & it is meant to have the information you would like to interact with.

### The @Model decorator

The `@Model` decorator provides a data modeler for your template in a programatic way. It is a [HTTP Parameter Decorator](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-mvc/controllers/http-handlers#http-parameter-decorators), which means, it is used & injected in the parameters of an HTTP handler.

`@Model` working as your data modeler for your template makes your code easier to interact with & more readable. Although, it does not have any important functionality more than serving as a helper for your template's data.

When using [ViewModel](https://doc.deno.land/https/raw.githubusercontent.com/mandarineorg/mandarinets/master/mvc-framework/core/modules/view-engine/viewModel.ts) (object injected from `@Model`), your method instead of returning  an object, **must** return this class as Mandarine will resolve the attributes added to the modeler at *request time*.

**Syntax:**

```
@Model()
```

## Usage

Example

```typescript
./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>
```

{% tabs %}
{% tab title="Controller" %}

```typescript

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();
```

{% endtab %}

{% tab title="Result" %}
![http://127.0.0.1:8080/path-template](https://2098605395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HNG2ebFcjvBcN6EEf%2F-M8NJaO-Uf_j4MWgJJhU%2F-M8NPDzbb2dCbW8EymU2%2FScreen%20Shot%202020-05-27%20at%207.12.09%20PM.png?alt=media\&token=5ea7af43-6f1c-48cd-964f-220e047e94ba)

![http://127.0.0.1:8080/manual-template](https://2098605395-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8HNG2ebFcjvBcN6EEf%2F-M8NJaO-Uf_j4MWgJJhU%2F-M8NPPUMmDxDKUV5CTIK%2FScreen%20Shot%202020-05-27%20at%207.12.00%20PM.png?alt=media\&token=17aac6db-94c4-4e47-b35c-2e0862e19609)
{% endtab %}
{% endtabs %}
