Trouble importing partials into a Leaf template

294 Views Asked by At

I am creating a single page web app, but for development I am writing it in sections. I want Leaf to serve up a base file which then includes the separate sections pulled from the different partial leaf template files.

I can use #get in a base template and #set in the include but I can only get this to work as a one on one link. I've seen there is a to import but I can't seem to get it to work. This is the code I currently have in my routes.swift

router.get("/test") { req -> Future<View> in
    let leaf = try req.make(LeafRenderer.self)
    let context = "Some data"
    return leaf.render("test", context)
} 

This is the code I have in my base.leaf file.

<!DOCTYPE html>
<html>
<body>

#get(test)

</body>
</html>

And this is the code I have in the test.leaf file.

#set('test'){
<h1> Hello there</h1>
}
#embed('base')

I thought I could use multiple #get commands but that does not seem to work as the route has to specify the partial for it to work (I think).

For example, I want to embed 3 child pages into one base template. In the base template I have the following code inside the tag.

#get(section1)
#get(section2)
#get(section3)

And I have three corresponding leaf templates for each section. How to I make sure that all sections get injected?

0

There are 0 best solutions below