
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
Mold builds on Go templates to provide a simple and familiar API for rendering web pages.
Create an HTML file named index.html.
{{define "head"}}
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
{{end}}
<h1>Hello from a <a href="//github.com/quarterlygod/mold">Mold</a> template</h1>
Create a new instance and render the view in an HTTP handler.
//go:embed index.html
var dir embed.FS
var engine, _ = mold.New(dir)
func handle(w http.ResponseWriter, r *http.Request){
engine.Render(w, "index.html", nil)
}
Check the examples directory for more.
Go package documentation is available at https://pkg.go.dev/github.com/quarterlygod/mold
Layouts provide the overall structure for your web pages. They define the common elements that are shared across multiple views, such as headers, footers, navigation menus, stylesheets e.t.c.
Inside a layout, calling render without an argument inserts the view's content into the layout's body.
To render a specific section, pass the section's name as an argument.
<!DOCTYPE html>
<html>
<head>
{{render "head"}}
</head>
<body>
{{render}}
</body>
</html>
The default layout can be overriden by creating a custom layout file and specifying it as an option for a new instance.
option := mold.WithLayout("path/to/layout.html")
engine, err := mold.New(fs, option)
Views are templates that generate the content that is inserted into the body of layouts.
Typically what you would put in the <body> of an HTML page.
<h3>Hello from Mold :)</h3>
The path to the view file is passed to the rendering engine to produce HTML output.
engine.Render(w, "path/to/view.html", nil)
Sections allow content to be rendered in specific parts of the layout.
They are defined within views with a define block.
The default layout is able to render HTML content within the <head> tag by utilising the head section.
{{define "scripts"}}
<script src="//unpkg.com/alpinejs" defer></script>
{{end}}
Partials are reusable template snippets that allow you to break down complex views into smaller, manageable components.
They are supported in both views and layouts with the partial function.
Partials are ideal sharing common logic across multiple views and layouts.
{{partial "path/to/partial.html"}}
An optional second argument allows customizing the data passed to the partial. By default, the view's data context is used.
{{partial "partials/user_session.html" .User}}
Go templates, while simple and powerful, can be unfamiliar when dealing with multiple template files.
Mold provides an intuitive and conventional higher-level use of Go templates for dealing with multiple template files.
MIT
You can support the author by donating on Github Sponsors or Buy me a coffee.
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.