Nest: @Render annotation - passing template name based on state

Created on 18 Mar 2019  路  4Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


@Render annotation argument is just a string. I can not dynamically change template depends on application state.

Expected behavior


I think it would be much better to resign from @Render annotation in favour of directly rendering a page. We can derive patterns from other technology stacks and possibly controllers should have a method to return in example this.render('template.hbs', { message }) instead of just an object with render annotation. There could be dedicated controller like MVCController (name to be discussed) with a render method.

Minimal reproduction of the problem with instructions

  1. Create simple controller.
  2. Add render annotation.
  3. Try to choose template dynamically based on value returned from a service.

What is the motivation / use case for changing the behavior?


It's possible in other technology stacks and others framework to dynamically render the page. @Render annotation looks not fully functional.

Environment


Nest version: 6.0.0


For Tooling issues:
- Node version: 10.15.3  
- Platform: Mac 

Others:

question 馃檶

Most helpful comment

Hey, cze艣膰,

Try to choose template dynamically based on value returned from a service.

You can inject response object using @Res() decorator and then use res.render() conditionally. Perhaps, it's worth adding to the documentation :)

All 4 comments

Hey, cze艣膰,

Try to choose template dynamically based on value returned from a service.

You can inject response object using @Res() decorator and then use res.render() conditionally. Perhaps, it's worth adding to the documentation :)

Cze艣膰 ;)

Yeah, you're right. I didn't think about it. It'd be useful to add such information to the documentation 馃槃. I can do it in a free time 馃憤

That would be awesome :) Let's track this issue here https://github.com/nestjs/docs.nestjs.com/issues/290 (PRs open). Thanks!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artjomzab picture artjomzab  路  33Comments

ArsalaBangash picture ArsalaBangash  路  27Comments

ZenSoftware picture ZenSoftware  路  35Comments

roeehershko picture roeehershko  路  27Comments

chaostheory picture chaostheory  路  34Comments