// LookupTemplate will lookup and return a template
777645
func (r *Store) LookupTemplate(ctx context.Context, name string) (string, []byte, bool) {
	oName := name
	_, store, name := r.getStore(ctx, name)
	tName, content, found := store.LookupTemplate(ctx, name)
	tName = filepath.Join(r.MountPoint(oName), tName)
	return tName, content, found
}
995636
func (c *Client) PrepareTemplate(p *PrepareTemplateParameter) (*Template, error) {
	obj, err := c.Request("prepareTemplate", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Template), err
}
696769
func (s *Set) getTemplate(name, sibling string) (template *Template, err error) {
	name = path.Clean(name)

	if s.developmentMode {
		s.tmx.RLock()
		defer s.tmx.RUnlock()
		if newName, fileName, foundLoaded, foundFile, _ := s.resolveNameSibling(name, sibling); foundFile || foundLoaded {
			if foundFile {
				template, err = s.loadFromFile(newName, fileName)
			} else {
				template, _ = s.templates[newName]
			}
		} else {
			err = fmt.Errorf("template %s can't be loaded", name)
		}
		return
	}

	//fast path
	s.tmx.RLock()
	newName, fileName, foundLoaded, foundFile, isRelative := s.resolveNameSibling(name, sibling)

	if foundLoaded {
		template = s.templates[newName]
		s.tmx.RUnlock()
		if !isRelative && name != newName {
			// creates an alias
			s.tmx.Lock()
			if _, found := s.templates[name]; !found {
				s.templates[name] = template
			}
			s.tmx.Unlock()
		}
		return
	}
	s.tmx.RUnlock()

	//not found parses and cache
	s.tmx.Lock()
	defer s.tmx.Unlock()

	newName, fileName, foundLoaded, foundFile, isRelative = s.resolveNameSibling(name, sibling)
	if foundLoaded {
		template = s.templates[newName]
		if !isRelative && name != newName {
			// creates an alias
			if _, found := s.templates[name]; !found {
				s.templates[name] = template
			}
		}
	} else if foundFile {
		template, err = s.loadFromFile(newName, fileName)

		if !isRelative && name != newName {
			// creates an alias
			if _, found := s.templates[name]; !found {
				s.templates[name] = template
			}
		}

		s.templates[newName] = template
	} else {
		err = fmt.Errorf("template %s can't be loaded", name)
	}
	return
}
434648
func (p *partial) template() (*Template, error) {
	if p.tpl == nil {
		var err error

		p.tpl, err = Parse(p.source)
		if err != nil {
			return nil, err
		}
	}

	return p.tpl, nil
}
898277
func NewTemplate() *Template {
	return &Template{
		AWSTemplateFormatVersion: "2010-09-09",
		Description:              "",
		Metadata:                 map[string]interface{}{},
		Parameters:               map[string]interface{}{},
		Mappings:                 map[string]interface{}{},
		Conditions:               map[string]interface{}{},
		Resources:                Resources{},
		Outputs:                  map[string]interface{}{},
	}
}
813646
func (s *TemplatesService) GetTemplate(accountID string, templateIdentifier string) (*templateResponse, error) {
	path := versioned(templatePath(accountID, templateIdentifier))
	templateResponse := &templateResponse{}

	resp, err := s.client.get(path, templateResponse)
	if err != nil {
		return nil, err
	}

	templateResponse.HttpResponse = resp
	return templateResponse, nil
}
282082
func (s *Store) GetTemplate(ctx context.Context, name string) ([]byte, error) {
	return s.storage.Get(ctx, s.templatefile(name))
}
1317423
func (q TemplateQuery) Template(name string) TemplateQuery {
	q.template = name
	return q
}
120939
func (o OSS) GetURLTemplate(option *media.Option) (url string) {
	return DefaultURLTemplateHandler(o, option)
}
1285484
func (mg *MailgunImpl) GetTemplate(ctx context.Context, name string) (Template, error) {
	r := newHTTPRequest(generateApiUrl(mg, templatesEndpoint) + "/" + name)
	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())
	r.addParameter("active", "yes")

	var resp templateResp
	err := getResponseFromJSON(ctx, r, &resp)
	if err != nil {
		return Template{}, err
	}
	return resp.Item, nil
}
677632
func (r *Render) TemplateLookup(t string) *template.Template {
	return r.templates.Lookup(t)
}
204697
func (a *PrintToPDFArgs) SetFooterTemplate(footerTemplate string) *PrintToPDFArgs {
	a.FooterTemplate = &footerTemplate
	return a
}
1182801
func (tg *TaskGroup) LookupTask(name string) *Task {
	for _, t := range tg.Tasks {
		if t.Name == name {
			return t
		}
	}
	return nil
}
1244605
func TransformTemplate(tpl *templatev1.Template, templateProcessor templateclientv1.TemplateProcessorInterface, namespace string, parameters map[string]string, ignoreUnknownParameters bool) (*templatev1.Template, error) {
	// only set values that match what's expected by the template.
	for k, value := range parameters {
		v := templateprocessing.GetParameterByName(tpl, k)
		if v != nil {
			v.Value = value
			v.Generate = ""
		} else if !ignoreUnknownParameters {
			return nil, fmt.Errorf("unexpected parameter name %q", k)
		}
	}

	name := localOrRemoteName(tpl.ObjectMeta, namespace)

	// transform the template
	result, err := templateProcessor.Process(tpl)
	if err != nil {
		return nil, fmt.Errorf("error processing template %q: %v", name, err)
	}

	return result, nil
}
731379
func (loader *FileSystemLoader) LoadTemplate(name string) (string, error) {
	f, err := os.Open(path.Join(loader.BaseDir, name))
	if err != nil {
		return "", err
	}
	b, err := ioutil.ReadAll(f)
	return string(b), err
}
1144730
func (s *Service) NewTemplate(w http.ResponseWriter, r *http.Request) {
	id, err := paramID("id", r)
	if err != nil {
		Error(w, http.StatusUnprocessableEntity, err.Error(), s.Logger)
		return
	}

	ctx := r.Context()
	dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
	if err != nil {
		notFound(w, id, s.Logger)
		return
	}

	var template chronograf.Template
	if err := json.NewDecoder(r.Body).Decode(&template); err != nil {
		invalidJSON(w, s.Logger)
		return
	}

	if err := ValidTemplateRequest(&template); err != nil {
		invalidData(w, err, s.Logger)
		return
	}

	ids := idgen.UUID{}
	tid, err := ids.Generate()
	if err != nil {
		msg := fmt.Sprintf("Error creating template ID for dashboard %d: %v", id, err)
		Error(w, http.StatusInternalServerError, msg, s.Logger)
		return
	}
	template.ID = chronograf.TemplateID(tid)

	dash.Templates = append(dash.Templates, template)
	if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
		msg := fmt.Sprintf("Error adding template %s to dashboard %d: %v", tid, id, err)
		Error(w, http.StatusInternalServerError, msg, s.Logger)
		return
	}

	res := newTemplateResponse(dash.ID, template)
	encodeJSON(w, http.StatusOK, res, s.Logger)
}
1076967
func newTemplate(source string) *Template {
	return &Template{
		source:   source,
		helpers:  make(map[string]reflect.Value),
		partials: make(map[string]*partial),
	}
}