code: func sortTemplates(templates map[string]Template, catalogSort bool) []Template {
  	chain := make([]Template, 0, len(templates)*2)
  
  	// build a full set of dependency chains
  	var keyList []string
  	var key string
  	var t Template
  	keyList = templateKeyList(templates, catalogSort)
  	for _, key = range keyList {
  		t = templates[key]
  		tlist := templateChainDependencies(t)
  		for _, tt := range tlist {
  			if tt != nil {
  				chain = append(chain, tt)
  			}
  		}
  	}
  
  	// reduce that to make a simple list
  	sorted := make([]Template, 0, len(templates))
  chain:
  	for _, t := range chain {
  		for _, already := range sorted {
  			if t == already {
  				continue chain
  			}
  		}
  		sorted = append(sorted, t)
  	}
  
  	return sorted
  }
docs: // sortTemplates puts templates in a suitable order based on dependices