Questions tagged [leaf]

For questions regarding the Leaf templating language that is used with the Vapor web framework

A description of Leaf from the documentation:

Leaf's goal is to be a simple templating language that can make generating views easier. There's a lot of great templating languages, use what's best for you, maybe that's leaf! The goals of leaf are as follows:

  • Small set of strictly enforced rules
  • Consistency
  • Parser first mentality
  • Extensibility

It was built specifically for the Vapor web framework that is used to create web apps with Swift.

Top questions:

69 questions
10
votes
3 answers

Image Upload in Vapor 3 using PostgreSQL

I'm following this guys Martin Lasek Tutorials and now i'm at "image upload". It seems that no one has the answer to the question "How do you upload images i Vapor 3" Db connection is ok, all the other values are saved. This is mye create method: …
Krister Moen
  • 438
  • 2
  • 15
9
votes
1 answer

Cannot render a computed property with Leaf in Vapor 3

I've been trying to render a computed property using the templating engine Leaf with Vapor 3, but so far no luck. If the same property is stored, everything works fine. If I make it computed, nothing is displayed in the web page. I can understand…
Diiaablo
  • 166
  • 1
  • 13
7
votes
3 answers

terminal vapor update is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead\n", output:

I had this error when I was doing a tutorial. I could not solve the problem. So, I deleted the project and made a new simple project to figure-out the issue,but still having the same issue. I am posting relevant code - package.swift code - //…
askit
  • 205
  • 4
  • 21
5
votes
2 answers

Leaf cannot find my template - Xcode 12 Vapor 4

I updated from Vapor 3 to 4, and Xcode 11 to 12. Now Leaf cannot find my *.leaf templates. I get a "noTemplateFile" error.
AlexMath
  • 567
  • 1
  • 6
  • 16
5
votes
2 answers

Server Side Swift: Navbar Toggle not working in Vapor 4 Leaf + Bootstrap

Configurations: Vapor 4 | Updated beta version & packages | macOS Catalina v.10.15.3 | XCode 11.4 beta 2 | Bootstrap CDN 4.4.1 I'm unable to toggle my navbar button. I'm not sure if it's a bug in Leaf. I've implemented Bootstrap and CSS in the right…
5
votes
2 answers

Leaf & Vapor 3 - Can't load css and images on view

I'm very new to Vapor and backend logic in general. I'm building a simple web app with Leaf and I'm trying to read data from a psql database and display them in a html/css (leaf) page. The problem is that when I pass my parameters to the page, it…
5
votes
3 answers

Swift Vapor Leaf deliver html in a variable

I need to create a complex html-table inside a Swift Vapor App. Problem is: Leaf doesn't seem to support counting up variables like #(somevar += 1) nor concatenating string variables like #(somevar1 + somevar2) So I decided to create my complex…
incredion
  • 51
  • 4
4
votes
1 answer

Add script action for buttons in html with Vapor

I am developing a web app with Swift 4 and Vapor 2.0. I have a method for a POST request which creates a new user: builder.post("user", "createUser") { (request) -> ResponseRepresentable in But I don't know how to add action for button in the…
lee
  • 7,955
  • 8
  • 44
  • 60
4
votes
1 answer

Vapor Swift - Compare two strings

I would like to compare a variable with a string in my leaf template. I get the variable through the controller in my template:
3
votes
0 answers

How to upload images from the browser to Amazon S3 using Vapor and Leaf?

I have set up AWS S3 bucket and I'm able to upload files there using Vapor 3 and Postman (PUT -request and with headers: ["x-amz-acl" : "public-read"]) but I would like to do that from the browser (I'm using leaf). So how can I upload image files…
anniina
  • 199
  • 1
  • 11
3
votes
1 answer

Using Leaf, the else condition isn't properly executed though the if one is

I have a simple Leaf template that I'd like to display Hello World in. #if(false) { All hail Apodron. } #else { Hello World } the page has no title and displays as: #else {Helloward} However, if I change this…
YannickR
  • 33
  • 4
3
votes
1 answer

Vapor/Leaf Custom Tag not returning correct value

I have registered a custom tag to return true if the index is odd and false if even as follows: class OddEvenTag: BasicTag { let name = "OddEven" func run(arguments: ArgumentList) throws -> Node? { guard arguments.count…
Nick
  • 4,820
  • 18
  • 31
  • 47
3
votes
0 answers

How to pass Leaf tag to another Leaf tag?

Is there a way to passing Leaf tag to another Leaf tag? For example, in my custom Leaf tag I return some html code: public func run( tagTemplate: TagTemplate, arguments: ArgumentList) throws -> Node? { return…
Varabaiba
  • 31
  • 1
2
votes
1 answer

How do you extend templates in Leaf using the #extend and #export tags in leaf?

The Leaf documentation doesn't seem to be working for me I can't figure out why. child.leaf #extend("index"): #export("hello"):

Welcome to Vapor!

#endexport #endextend index.leaf
2
votes
1 answer

How to format a date field in a Leaf template using Vapor 4

In a list, I want to show dates fetched form the database. If I use: #Date(timeStamp: appointment.appointmentDate,localizedFormat: "E, dd-MM-yyyy") I would expect: Wed, 30/12/2020 BUT I get Wed, 12/30/2020 which I find very strange since I…
Glenn
  • 2,808
  • 2
  • 24
  • 30
1
2 3 4 5