@Render Decorator

This article requires knowledge of Controllers & HTTP Handlers

Main

In order to make an endpoint "renderable", it is necessary to decorate your HTTP Handler with the @Render decorator. The @Render decorator will tell Mandarine's MVC core that such endpoint is expecting to be rendered on the client's browser and thus Mandarine's MVC core will be expecting a renderable content.

Usage

Syntax:

See Mandarine.MandarineMVC.TemplateEngine.RenderingOptions

See Mandarine.MandarineMVC.TemplateEngine.Engines

@Render(template: string, 
options?: Mandarine.MandarineMVC.TemplateEngine.RenderingOptions, 
engine?: Mandarine.MandarineMVC.TemplateEngine.Engines)
  • template

    • Used to specify the path of your template inside your template's directory. This means, you must not specify the whole path as it will be resolved.

    • Used to specify the content of the template instead of using a file.

      • If a manual template is used, Mandarine.MandarineMVC.TemplateEngine.RenderingOptions.manual must be true

  • options

    • Used to specify the behavior of loading the template.

      • manual If set to true, template is not considered a file but a string content.

  • engine

    • Engine to be used when rendering the template

Example

./src/main/resources/templates/index-template.html

<h2>Hello Bill! Nice to see you here again</h2>
myfile.ts

import { Controller, GET, Render, MandarineCore } from "https://deno.land/x/mandarinets/mod.ts";

@Controller()
export class MyController {

    @GET('/path-template')
    @Render('index-template.html')
    public httpHandler() {
    }
    
    @GET('/manual-template')
    @Render(`<h2>This is a manual template</h2>`, { manual: true })
    public httpHandler2() {
    }
    
}

new MandarineCore().MVC().run();

Last updated