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

default(x, value) only works properly with names and exists("x") and existsIn(y, "x") only works properly with strings #203

Open
brycelelbach opened this issue Jun 5, 2021 · 0 comments

Comments

@brycelelbach
Copy link
Contributor

brycelelbach commented Jun 5, 2021

Inja has three constructs which query names that may possibly not exists.

  • default, which takes the name as a name, e.g. default(x) not default("x"). If a string is provided instead of a name, the string is returned without an error.
  • exists and existsIn, which take the name as a string, e.g. exists("x") not exists(x). If a name is provided instead of a string, these functions work if the name exists, and a render error occurs if the name does not exist.

Check it out on Godbolt here.

This dichotomy is a bit unintuitive. It's also restrictive - you might want to dynamically construct or look up a name as a string and then pass it to default, but you cannot do that today.

I think all of these functions should accept either names or strings and do the right thing with them. That would mean extending exists and existsIn to take strings, and changing the behavior of default when a string is passed in.

@brycelelbach brycelelbach changed the title default(x, value) does not require quotes around the name but exists("x") and existsIn(y, "x") do default(x, value) accepts both strings and names, but exists("x") and existsIn(y, "x") only accept names Jun 5, 2021
@brycelelbach brycelelbach changed the title default(x, value) accepts both strings and names, but exists("x") and existsIn(y, "x") only accept names default(x, value) accepts only names and exists("x") and existsIn(y, "x") only accept strings Jun 5, 2021
@brycelelbach brycelelbach changed the title default(x, value) accepts only names and exists("x") and existsIn(y, "x") only accept strings default(x, value) only works properly with names and exists("x") and existsIn(y, "x") only works properly with strings Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants