# candy-deno-template-engine **Repository Path**: candyjs/candy-deno-template-engine ## Basic Information - **Project Name**: candy-deno-template-engine - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-18 - **Last Updated**: 2025-03-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Simple Template Engine ## Usage #### 1. Change the defaultView to @luban/mvc-template/View ```typescript // main.ts import App from '@luban/framework/web/Application'; import Main from '@luban/framework'; import View from '@luban/mvc-template/View'; const app = new App({ id: 'demo', appPath: Deno.cwd() + '/app', defaultView: new View(), }); ``` #### 2. Render a template in controller ```typescript // app/controllers/index/IndexController.ts import type HttpRequest from '@luban/framework/http/HttpRequest'; import HttpResponse from '@luban/framework/http/HttpResponse'; import Controller from '@luban/framework/web/Controller'; export default class IndexController extends Controller { public override async run(_request: HttpRequest): Promise { const posts = [ { id: 1, title: 'Hello' }, { id: 2, title: 'World' }, ]; const html = await this.render('home', { posts, }); return HttpResponse.fromHTML(html); } } ``` #### 3. Write the template file ```html // app/views/index/home.html Demo <% for(const v of $template.$data.posts){ %>

<%= v.title %>

<% } %> ```