Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with Render() #602

Open
LANWrench opened this issue Aug 18, 2020 · 2 comments
Open

Help with Render() #602

LANWrench opened this issue Aug 18, 2020 · 2 comments
Labels
type: fix Issues describing a broken feature.

Comments

@LANWrench
Copy link

I was trying to...
I am trying to use Render() with EJS.

The problem:
First off I want to thank you for this library, it really awesome and have really enjoyed using it.

I have a new project I am working on and decided that EJS would be best for it. I am using the Render decorator and the first call it works perfectly but any subsequent calls that use a different template will get the first template returned.

For example, if I request /puppies it will return the template from puppies.ejs. If I then request /kittens, debug shows the template file for puppies still being returned.

I am using the koa-ejs module with this, but have tested with koa-views and get the same result.

Here are my files:

// server.ts
import { createKoaServer } from 'routing-controllers';
import Koa from 'koa';
import * as HttpStatus from 'http-status-codes';
import render from 'koa-ejs';
import * as path from 'path';
import 'reflect-metadata';

const app: Koa = createKoaServer({
  controllers: [__dirname + "/controllers/**/*{.ts,.js}"]
});

render(app, {
  root: path.join(__dirname, 'views'),
  layout: 'layout',
  viewExt: 'ejs',
  cache: false,
  debug: true
});

app.listen(3001), () => {
  console.log(`Server listening on port 3001`)
};



// kittens.controller.ts
import {Controller, Get, Render } from 'routing-controllers';

@Controller('/kittens')
export class KittensController {
    constructor(){}

    @Render('kittens')
    @Get()
    getKittens() {
        return {
            animal: 'kittens'
        }
    }
}



//puppies.controller.ts
import {Controller, Get, Render} from 'routing-controllers';

@Controller('/puppies')
export class PuppiesController {
    constructor(){}

    @Get()
    @Render('puppies')
    getPuppies() {
        return {
            animal: 'puppies'
        }
    }
}

Templates:

<!-- layout.ejs -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>EJS Test</title>
</head>
<body>

  <%- body %>

</body>
</html>



<!-- puppies.ejs -->
This is the puppies  page.


<!-- kittens.ejs -->
This is the kittens  page.

I am a network engineer by day, learning app development by night so if my code doesn't look good feel free to point it out.

Thank you very much for your time and any help you may be able to provide.

@AnthonyACE
Copy link

Same Problem

@nanyuantingfeng
Copy link

I had the same problem and have fixed it:

#780

@attilaorosz attilaorosz added the type: fix Issues describing a broken feature. label Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: fix Issues describing a broken feature.
Development

No branches or pull requests

4 participants