Skip to content

Version 0.28.0

Compare
Choose a tag to compare
@chasefleming chasefleming released this 15 Aug 00:06
· 12 commits to main since this release
114679a

🚀 New Features

Introducing Fragment for Grouping Elements

You can now use the Fragment function to group multiple HTML elements together without adding an extra wrapper element to the DOM. This is particularly useful when you want to merge nodes into a single parent without adding unnecessary structure.

Usage Examples

Below is an example of how you can utilize the Fragment function in your Go code:

import (
    "github.com/chasefleming/elem-go"
)

func main() {
    nodes1 := []elem.Node{
        elem.P(nil, elem.Text("1")),
        elem.P(nil, elem.Text("2")),
    }
    nodes2 := []elem.Node{
        elem.P(nil, elem.Text("3")),
        elem.P(nil, elem.Text("4")),
    }

    content := elem.Div(nil,
        elem.P(nil, elem.Text("0")),
        elem.Fragment(nodes1...),
        elem.Fragment(nodes2...),
    )

    html := content.Render()
    fmt.Println(html)
}

This code will produce the following HTML output:

<div><p>0</p><p>1</p><p>2</p><p>3</p><p>4</p></div>

🙏 Thanks to Contributors