I am making an android application with Kotlin using the framework Ktor where the android device act as the server and you can connect to it using your browsers in other devices. I have been able to get to the spot where my .hbs file (which is the template for creating a html page) displays all data in the browser. When I pass single data like String, Int, Bool from the backend to this .hbs page. But when I try to pass a list or arraylist to the .hbs page and loop through it, I cannot displays the content from the loop.
This is how I set up my templates
fun Application.configureTemplating(){
install(Mustache){
mustacheFactory = DefaultMustacheFactory("templates")
}
}
This is how I set up my routing
fun Application.configureRouting() {
routing {
get("/") {
call.respondRedirect("web")
}
route("web") {
get{
val directoryFiles = DataManager.getRawData(Const.ROOT_FOLDER_KEY)
call.respond(MustacheContent("index.hbs", mapOf("directoryFiles" to directoryFiles)))
}
}
}
}
This is my .hbs file
<html>
<head>
</head>
<body>
<h3>Folders</h3>
<div class="container">
{{#directoryFiles}}
<p>{{name}}</p>
{{/directoryFiles}}
</div>
</body>
</html>
My "directoryFiles" prints
[{"extension":"","fileType":"FOLDER","name":"Pictures","path":"\/storage\/emulated\/0\/Pictures","sizeInMB":0.003326416015625,"subFiles":5},{"extension":"","fileType":"FOLDER","name":"Android","path":"\/storage\/emulated\/0\/Android","sizeInMB":0.003326416015625,"subFiles":3}].
when I try to debug it. When I try to display the only the list in the browser it shows
, but I try to loop through it and display it's content, the content doesn't show and it does not display an errors either.
This is my mustache gradle dependency and the ktor version is 2.0.1
implementation("io.ktor:ktor-server-mustache:$ktor_version")