raymond icon indicating copy to clipboard operation
raymond copied to clipboard

Helpers dont seem to work with variadic parameters

Open quii opened this issue 8 years ago • 3 comments


raymond.RegisterHelper("addParamsToLink", func(link string, params ...string) string {
  // details not important
  return "banana"
})


template, _ := raymond.Parse(`{{addParamsToLink baseLink parameter second}}`)

// and a test

t.Run("adds two parameters to url with parameter", func(t *testing.T) {
	context := map[string]string{
		"baseLink":  "localhost:8080/?time=now",
		"parameter": "drink=beer",
		"second":    "place=bar",
	}
	result, _ := template.Exec(context)
	assert.Equal(t, "localhost:8080/?time=now&drink=beer&place=bar", result, "adds two parameters simple url")
	})

The test fails because the helper seems to return an empty string. I suspect it is panic-ing silently.

If I remove the vararg-ness it returns banana

quii avatar Apr 19 '17 10:04 quii

Did you find any solution to above?

ddivanshu avatar Jul 15 '20 14:07 ddivanshu

any update or has anyone found a solution to this?

ivoputzer avatar Oct 15 '21 10:10 ivoputzer

I fixed this on a fork of the mailgun/raymond repo: https://github.com/mailgun/raymond/compare/master...pbedat:raymond:master

pbedat avatar Nov 03 '23 10:11 pbedat