Skip to content

HTMLView

Josh Wright edited this page Jan 14, 2021 · 4 revisions

HTMLView

A protocol for defining HTML views to return to a client.

public protocol HTMLView: ResponseConvertible

Usage:

struct HomeView: HTMLView {
    let title: String
    let favoriteAnimals: [String]

    var content: HTML {
        HTML(
            .head(
                .title(self.title),
                .stylesheet("styles.css")
            ),
            .body(
                .div(
                    .h1("My favorite animals are"),
                    .ul(.forEach(self.favoriteAnimals) {
                        .li(.class("name"), .text($0))
                    })
                )
            )
        )
    }
}

router.route(.GET) {
    HomeView(
        title: "My Website",
        favoriteAnimals: ["Platypus", "Tapir", "Lemur"]
    )
}

Inheritance

ResponseConvertible

Requirements

content

The HTML content of this view.

var content: HTML
Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally