Collecting my attempts to improve at tech, art, and life

SiYuan Template Files

Using template snippets to insert predefined content to SiYuan Note

Templates

  • Markdown files. You put them in data/templates​​.
  • Templating logic with Go’s text/template​​.
    • ​.action{action}​​ instead of {{action}}​​
    • Additional functionality via Sprig
    • Remember Go’s thing about date formatting

Template Variables

Beyond whatever’s defined by Sprig

Variable Description
​title​​ current document’s name
​id​​ current document’s id
​name​​ current document name 🤔
​alias​​ current document alias
​queryBlocks​​ result of a db query as blocks
​querySpans​​ result of a db query as spans
​parseTime​​ parse a string into time.Time​​

Template Invocation

Command: /Template​​

  1. Invoking /Template​​ pulls up template list along with expected output.
  2. Select template
  3. Template is entered at point

Resources

Date Formatting

Date formatting in templates.

via time package constants

const (
	Layout      = "01/02 03:04:05PM '06 -0700" // The reference time, in numerical order.
	ANSIC       = "Mon Jan _2 15:04:05 2006"
	UnixDate    = "Mon Jan _2 15:04:05 MST 2006"
	RubyDate    = "Mon Jan 02 15:04:05 -0700 2006"
	RFC822      = "02 Jan 06 15:04 MST"
	RFC822Z     = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
	RFC850      = "Monday, 02-Jan-06 15:04:05 MST"
	RFC1123     = "Mon, 02 Jan 2006 15:04:05 MST"
	RFC1123Z    = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
	RFC3339     = "2006-01-02T15:04:05Z07:00"
	RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
	Kitchen     = "3:04PM"
	// Handy time stamps.
	Stamp      = "Jan _2 15:04:05"
	StampMilli = "Jan _2 15:04:05.000"
	StampMicro = "Jan _2 15:04:05.000000"
	StampNano  = "Jan _2 15:04:05.000000000"
)

Sprig

Useful template functions for Go Templates

Pasting from their front page until I dig deeper on my own:

The Sprig library provides over 70 template functions for Go’s template language.

Related


Added to vault 2024-01-28. Updated on 2024-01-28