-
Notifications
You must be signed in to change notification settings - Fork 166
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
A way to evaluate a String inside a template #230
Comments
Why don't you just use something like this
|
@ebussieres I agree there is a critical point missing in my question! : The "user.firstName" key is dynamically built, I don't know it at compile time! This would be a better example :
|
Ah ok i see now ! It don't think it's supported but adding a evaluate tag would be useful I agree. However, it'll be difficult to implement. The lexer splits the template into Token objects. The string "user.firstName" represent a single String Token. If we want to evaluate it, we need to split it in 3 Tokens
If we add a evaluate tag, it'll be too late because it runs after the lexer and manipulates token. |
If it's only the attribute name that is dynamic but the root variable isn't, you can use the square bracket notation to look up dynamic attributes:
But if the root variable is dynamic, i.e. "user", then I don't think there's currently a good solution. Feature request #235 is for string interpolation which I believe will solve your issue. If you think that's the case, we'll close this task as a duplicate. |
If it's possible to pass a root variable name to that string interpolation construct, I'm pretty sure it would do the trick, yes! No problem for me if you close this task as a duplicate. Thanks. |
So, after checking the PR #240 , the current suggested String Interpolation solution doesn't help with this issue. |
Yup, I was thinking about this issue a bit more and I think we'll need to come up with something a bit more creative. I'll have to take a look at what other template engines are doing. I believe twig uses a special variable called |
This is pretty hacky, but if I've understood what you are looking for correctly, couldn't you implement a function like this:
and use it like so:
|
Hi guys Would such interpolation be applicable to dynamic generation of macro names? For Eg :
I know this may be a tall order; Our code currently has way too many conditional macro selector code :( Thanks |
Resolved by adding the DynamicAttributeProvider interface |
Let's say using this Map :
Then something like this would be nice:
==> 'John'
I'm not sure if this would be useful for many people, but it would be for me!
The text was updated successfully, but these errors were encountered: