https://kotlinlang.org logo
#ktor
Title
# ktor
c

Cherif Bouchelaghem

03/09/2024, 10:06 PM
Hello, I'm trying to build links like in https://ktor.io/docs/type-safe-routing.html#resource_links by using the overrloaded href function but without success any one faced this issue before?
I think I get it, the overridden
href
should be invoked in the context of the Application or any instance than extends the application like a
Resource
Copy code
this@dashboard.application.apply { 
    href(Routes.Dashboard)
}
The problem I'm using HTML DSL templates and I need to use
href(MyResource)
inside the template, how to get the instance of the app or a resource inside the template?
Ok, I passed the application instance to my template class and used it inside the body/
Copy code
class RootTemplate(private val pageTitle: String, private val app: Application) : Template<HTML> {
...
 body("has-navbar-fixed-top") {
            app.apply {
               a {
                  href = href(Routes.Dashboard) 
                  
              }
            }
}