HTML DSL placeholder insert cannot be called with argument supplied

47 views Asked by At

I am building a few Html Templates using Kotlin DSL templating: https://ktor.io/docs/html-dsl.html#templates

But, something doesn't make sense in my approach:

class LayoutTemplate() : Template<HTML> {
    val titleText = Placeholder<FlowContent>()
    val header = TemplatePlaceholder<FlowContent>()
    val footer = TemplatePlaceholder<FlowContent>()

    override fun HTML.apply() {
        head {
            title {
                insert(titleText)
            }
        }

        body {
            insert(HeaderTemplate(), header)
            h1 {
                insert(titleText)
            }
            div {
                id = "content"
                insert(content)
            }
            insert(FooterTemplate(), footer)
        }
    }
}

class HeaderTemplate : Template<BODY> {
    override fun BODY.apply() {
        div {
            id = "header"
            h1 { +"Header" }
        }
    }
}

class FooterTemplate : Template<BODY> {
    override fun BODY.apply() {
        div {
            id = "footer"
            h1 { +"Footer" }
        }
    }
}

But, I get an error on insert(HeaderTemplate(), header) like: None of the following functions can be called with the arguments supplied.

Similarly insert(titleText) shows:

Type mismatch. Required: FlowContent Found: TITLE

Can someone help on what I am not understanding?

0

There are 0 answers