Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass int/bool/float to template #9

Open
sven0726 opened this issue Oct 31, 2018 · 1 comment
Open

How to pass int/bool/float to template #9

sven0726 opened this issue Oct 31, 2018 · 1 comment
Labels

Comments

@sven0726
Copy link

template := "http://{{host}}/?q={{query}}&foo={{bar}}"
	t := fasttemplate.New(template, "{{", "}}")
	s1 := t.ExecuteString(map[string]interface{}{
		"host":  "google.com",
		"query": url.QueryEscape("hello=world"),
		"bar":   22,
})

In my case, there are always int/bool/float type to template.

Error:

panic: tag="bar" contains unexpected value type=22. Expected []byte, string or TagFunc
@valyala
Copy link
Owner

valyala commented Oct 31, 2018

There are two options exist:

  1. Manually convert int/bool/float to string before passing to template.
  2. Implement TagFunc for int/bool/float.

Another option is to use quicktemplate instead. It supports int and float out of the box, while bool template may be easily implemented with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants