Skip to content

Reuse HML components #232

@beastgrim

Description

@beastgrim

So I have reusable HTML component, ex textfield. For example its look like this:
textfield.leaf

<div class=#(class)>
    <p>
        <label class="label">#(title)</label>
        <br>
        <span data-name="#(name)">
        <input size="40" id="#(id)" placeholder="#(placeholder)" value="#(value)" type="#(type)" name="#(name)" accept="#(accept)">
        </span>
    </p>
</div>

Also I have data for this HTML component:

struct TextFiled: Encodable {
    var `class`: String?
    var title: String?
    var name: String?
    var placeholder: String?
    var value: String?
    var type: String?
    var accept: String?
}

struct Form: Encodable {
    var email: TextFiled
    var phone: TextFiled
    var address: TextFiled
}

I send data to render like this:

func routes(_ app: Application) throws {
    app.get { req async throws in
        return try await req.view.render("index", Form(
            email: TextFiled(...),
            phone: TextFiled(...),
            address: TextFiled(...)
       ))
    }
}

And I can't realise how to pass data to reusable textfields?
Intuitively it should be something like this, but it doesn't work.

<div class="form">
#extend("textfield") { #(email) }
#extend("textfield") { #(phone) }
#extend("textfield") { #(address) }
</div>

Thanks for any help how to do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions