Skip to content

HTML Content as init parameter #76

Answered by sliemeobn
bgisme asked this question in Q&A
Discussion options

You must be logged in to vote

you almost got it right, but you need to make MyDiv generic over the type of supplied.
In your case, you are using the type Content, which is the associated type of the HTML protocol (ie: what var content returns) - that is why the swift type checker fails to figure out what is going on ; )
also, no need to call .render() in there.

you can see this in practice in the example project (under Examples/HummingbirdDemo/Sources/App/Pages.swift)

your snippet should look something like this:

public struct MyDiv<Supplied: HTML>: HTML {
    public var features: [String]
    
    public var supplied: Supplied
    
    public init(
        features: [String],
        @HTMLBuilder content: () -> Supplied

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bgisme
Comment options

Answer selected by bgisme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants