Skip to content

怎么把一段html字符串,渲染到模板? #351

@axetroy

Description

@axetroy
  • Node Version:
  • Egg Version:
  • Plugin Name:
  • Plugin Version:
  • Platform:

想渲染markdown,用marked去读取,编译成html之后,如何插入模板。

// controller/home
module.exports = app => {
  class HomeController extends app.Controller {
    * index() {
      const data = {};

      let text = fs.readFileSync(path.join(app.baseDir, 'README.md'));
      data.content = marked(text + '');

      yield this.ctx.render('home.tpl', data);
    }
  }
  return HomeController;
};
<!-- home.tpl -->
<html>
<head>
    <title>Egg HackerNews Clone</title>
</head>
<body>
<div>
{{content}}
</div>
</body>
</html>

渲染出来的是div内的纯字符串
求教如何渲染到innerHTML,而不是innerText

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions