Skip to content

feature: anonymous templ functions #1327

Description

@thisguycodes
func test() templ.Component {
	comp := templ() {
		<div>content</div>
	}
	return comp()
}

For a less contrived use case: I want to attach some metadata to my pages, basically frontmatter, and it'd be nice to be able to do things inline.

Right now, this works:

templ myPage(fr pagedb.Front) {
	if fr.Bool("isReal") {
		<div>I'm a real boy!</div>
	} else {
		<div>sadly just a puppet...</div>
	}
}

func init() {
	pagedb.Register(myPage(), map[string]any{
		"meta": "data",
		"isReal": false,
	})
}

But being able to put it inline would unlock a few things when it comes to mimicking the workflow / format of other frontmatter site systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions