Alternate Delimiters



Hof uses Go’s text/template package which defaults to {{ & }} for delimiters. This can conflict with other systems, so hof enables you to change them.

Per-file Template Delimiters

You can configure delimiters per-file by setting the TemplateDelims field on a gen.#File.

per-file template delimiters

MyGen: gen.#Generator & {

	// ...

	Out: [...gen.#File] & [
		// A file with the default {{ }} delimiters
		{
			TemplateContent: "Val.a = '{{ .Val.a }}'\n"
			Filepath:        "default.txt"
		},

		// Alternate delims
		{
			TemplateContent: "Val.a = '{% .Val.a %}'\n"
			Filepath:        "altdelim.txt"

			// Set alternate delimiters to anything you like
			TemplateDelims: {
				LHS: "{%"
				RHS: "%}"
			}
		},
	]
}

Per-glob Template Delimiters

You can set delimiters when loading Templates and Partials when you have a directory of files which need alternative delimiters, or you prefer a different syntax. Set the Delims field in the configuration.

per-glob template delimiters

MyGen: gen.#Generator & {

	// ...

	Templates: [{
		// Loaded templates with the default {{ }} delimiters
		Globs: ["templates/*"]
		TrimPrefix: "templates/"
	}, {
		// Loaded templates with the default alternate delimiters
		Globs: ["templates/alt/*"]
		TrimPrefix: "templates/"
		Delims: {
			LHS: "{%"
			RHS: "%}"
		}
	}]
}