vapor / template-kit

📄 Easy-to-use foundation for building powerful templating languages in Swift.
MIT License
46 stars 17 forks source link

Nested For Loops not Working Properly #63

Closed Cartisim closed 4 years ago

Cartisim commented 4 years ago

There is a current potential bug where children in for loops can not be accessed in leaf. Here is an Example.

 '//Leaf Code
 #for(dog in dogs) {
   <table>
  <tr>
     <td>#(dog.name)</td>
 </tr>
    #for(type in dog.breed) {
 <tr>
    <td>#(type.breeds)</td>
 //Expected output from Type.breeds ["lab", "terrier", "retriever"]
 </tr>
 }
  <table>  
 }

 //Swift Request
  func BreedHandler(_ request: Request) throws -> Future<View> {
    return try request.parameters.next(Dog).flatMap(to: View.self, { (dog) ->    EventLoopFuture<View> in
            return try request.parameters.next(Type).flatMap(to: View.self, { (type) -> EventLoopFuture<View> in
                let dog = type.dog.get(on: request)
                return type.flatMap { (dog) -> EventLoopFuture<View> in

                    return try type.breeds.query(on: request).all().flatMap(to: View.self, { (breeds) -> EventLoopFuture<View> in

                        let breeds = typeBreeds(id: type.id, dogID: dog.id, breeds: breeds)

                        let context = premiumSubCourseContext(title: "Dogs", dogs: dog, type: breeds)

                        return try request.view().render("Premium/dogBreeds", context)
                    })

                }
            })
        })
    }
  '

The Goal is simply to loop through Dogs find a certain dog, then loop through the type of breeds in that dog a list them in the table. So Fito -> Lab, Golden Retriever, Jack Russell Terrier. There seems to be a bug in the framework.

Thanks a bunch guys,

Cole

0xTim commented 4 years ago

@Cartisim is the above just pseudocode? Because in the context you have a single dog and are then using dogs in the template

Cartisim commented 4 years ago

My Apologies, yes it is pseudo code.

0xTim commented 4 years ago

Closing as template kit is not used with Vapor 4 and new behaviour is in LeafKit - if this is still an issue please create an issue on that repo. Thanks!