Mandarine.TS
Latest
Latest
  • Mandarine.TS
  • Getting started
    • Installing Deno Runtime
    • Setting up Environment
    • Quick Example
  • Concepts
  • Mandarine Project Structure
  • Mandarine CLI
    • CLI Reference
      • mandarine new
      • mandarine generate
      • mandarine run
  • Mandarine Core
    • Core Initialization
    • Mandarine.json
    • Dot env file
    • Properties
      • The @Value Decorator
    • Components
      • Controller
      • Middleware
      • Repository
      • Component
      • Service
      • Configuration
      • Manual Component
    • Dependency Injection
      • Accessing DI container
    • Resource Handlers
      • Resource Handler Registry
      • Resource Handler
      • Resource Resolver
  • Mandarine MVC
    • Web MVC
    • Controllers
      • Routes
        • Parameterized Routes
      • HTTP Handlers
      • @ResponseStatus
    • Custom Middleware
    • Session Middleware
    • CORS Middleware
    • Template Engine
      • @Render Decorator
      • Accessing data from template
    • Launching web-app
    • Serving Static Content
    • Multipart Form Data
  • Mandarine Security
    • Sessions
  • Mandarine Data
    • ORM
      • Data source
      • Models
      • Repositories
        • Interacting with data
        • Updating data
    • Mandarine Query Language
  • Resources
    • Changelog
  • Plugins
    • Optional
    • Promise Repeater
Powered by GitBook
On this page
  • Main
  • Usage

Was this helpful?

  1. Mandarine MVC
  2. Template Engine

@Render Decorator

PreviousTemplate EngineNextAccessing data from template

Last updated 4 years ago

Was this helpful?

This article requires knowledge of &

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

See

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

Controllers
HTTP Handlers
Mandarine.MandarineMVC.TemplateEngine.RenderingOptions
Mandarine.MandarineMVC.TemplateEngine.Engines
# http://127.0.0.1:8080/path-template
# http://127.0.0.1:8080/manual-template