You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like a bug, that with action in templates produce error with missingkey=error.
Due the documentation with action is made for checking if pipeline is empty, and perfectly fits in logic, for example, if foo has key "bar", then print something. But with missingkey=error option it fails all template generation with error. (http://play.golang.org/p/kmmkkrHZYI)
I found a workaround for this case, using index function. It works as expected, and does not produce errors on not existent key. But it makes templates less readable, and, I think, simple addressing should have same behaviour.
The text was updated successfully, but these errors were encountered:
This is exactly how it should work. The with action does not check for the presence of a field, but rather whether the field's value is non-zero. See this complementary example that uses a struct instead of a map: http://play.golang.org/p/b_Opy4892i
adg
changed the title
with on not existing key in map produce error with missingkey=error
tex/template: with on not existing key in map produce error with missingkey=error
Nov 5, 2015
adg
changed the title
tex/template: with on not existing key in map produce error with missingkey=error
text/template: with on not existing key in map produce error with missingkey=error
Nov 5, 2015
It looks like a bug, that
with
action in templates produce error withmissingkey=error
.Due the documentation
with
action is made for checking if pipeline is empty, and perfectly fits in logic, for example, if foo has key "bar", then print something. But withmissingkey=error
option it fails all template generation with error. (http://play.golang.org/p/kmmkkrHZYI)I found a workaround for this case, using
index
function. It works as expected, and does not produce errors on not existent key. But it makes templates less readable, and, I think, simple addressing should have same behaviour.The text was updated successfully, but these errors were encountered: