Search code examples
swiftvaporskeleton-css-boilerplate

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. 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:

[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:

    #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. I've also tried creating a new Vapor 2 project from scratch (using a fresh install of vapor) and it behaves the same. It seems odd that something so fundamental doesn't work out of the box.


Solution

  • It turns out that although the default renderer for Droplet is 'leaf', the default setting in Config is 'static'. Putting:

     "view": "leaf"
    

    into Config/drop.json fixed the problem.