简体   繁体   English

蒸气未通过Leaf渲染文件

[英]Vapor not rendering file through Leaf

I am trying to add a Skeleton-templated view to a recent Vapor 2 app that, so far, only produces JSON output with a MySQL database. 我正在尝试将Skeleton模板视图添加到最近的Vapor 2应用程序中,到目前为止,该应用程序仅使用MySQL数据库生成JSON输出。 If I use the following minimal code: 如果我使用以下最少的代码:

    get("viewTest")
    { req in
        let params = try Node(node: [ "name": "nick"])
        return try self.view.make("index",Node(node:params))
    }

The file index.leaf exists in the Resources/Views folder and the documentation suggests that omitting the .leaf suffix is fine, but doing so gets: index.leaf文件存在于Resources/Views文件夹中,并且该文档建议省略.leaf后缀是可以的,但是这样做可以:

[Data File Error: unable to load file at path /Users/test/Library/Mobile Documents/com~apple~CloudDocs/Apps/Vapor/testServer/Resources/Views/index]

However, if I put the suffix in explicitly, self.view.make("index.leaf",Node(node:params)) , the contents of the file are output without being rendered: 但是,如果我将后缀显式放入self.view.make("index.leaf",Node(node:params)) ,则文件的内容将被输出而不会被渲染:

    #extend("base") #export("body") {#(name)}

I have tried putting the code directly into Main.swift and that makes no difference and putting it into a handler. 我尝试将代码直接放入Main.swift中,将其放入处理程序中没有区别。 I've also tried creating a new Vapor 2 project from scratch (using a fresh install of vapor) and it behaves the same. 我还尝试过从头开始创建一个新的Vapor 2项目(使用全新安装的蒸气),并且其行为相同。 It seems odd that something so fundamental doesn't work out of the box. 如此基本的东西开箱即用似乎很奇怪。

It turns out that although the default renderer for Droplet is 'leaf', the default setting in Config is 'static'. 事实证明,尽管Droplet的默认渲染器为“叶子”,但Config中的默认设置为“静态”。 Putting: 把:

 "view": "leaf"

into Config/drop.json fixed the problem. 进入Config/drop.json解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM