vapor / leaf

🍃 An expressive, performant, and extensible templating language built for Swift.

Home Page:https://docs.vapor.codes/4.0/leaf/getting-started

Repository from Github https://github.comvapor/leafRepository from Github https://github.comvapor/leaf

empty tag not found

zarghol opened this issue · comments

When I want to use the #empty(variable) syntax, I got this error :

ParseError.tagTemplateNotFound("empty")

In the documentation, the empty tag is used to test is a variable is empty, but it doesn't work. When I go into the Constants.swift of Leaf, there is no empty...

thanks for help !

Can you provide a link to where it says #empty ?

It was at this url : https://vapor.github.io/documentation/guide/leaf.html at the Chaining paragraph.
When I refreshed the page, the page changed and no longer showed #empty...
Fortunately, I took a screenshot before to refresh :
capture d ecran 2016-12-15 a 23 48 37

to use it in my project, I wrote it as a custom tag :

import Foundation
import Vapor
import Leaf

class Empty: BasicTag {
    let name = "empty"
    
    func run(arguments: [Argument]) throws -> Node? {
        guard arguments.count > 0 else {
            return Node("empty")
        }
        for arg in arguments {
            guard let val = arg.value, !val.isNull else  {
                return Node("empty")
            }
            if let arr = val.array, arr.count == 0 {
                return Node("empty")
            }
            
            if let dico = val.nodeObject, dico.count == 0 {
                return Node("empty")
            }
        }
        
        return nil
    }
}

I found in the doc repo which commit delete this :
vapor/docs@9ad6d8e