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

Bug: Interpolation #21

Closed
chasegiunta opened this issue Jan 14, 2020 · 4 comments
Closed

Bug: Interpolation #21

chasegiunta opened this issue Jan 14, 2020 · 4 comments

Comments

@chasegiunta
Copy link

{% include "#{bar}" %}
with singleQuotes set to true will output:
{% include 'bar' %}

☝️ Couple of things here:
Even if singleQuotes is set to true, ideally since double quotes are required for "string#{interpolation}" to work, the singleQuote setting should only convert double quotes to single quotes if #{ } is not present.
https://twig.symfony.com/doc/3.x/templates.html#string-interpolation

The other other obvious weird thing going on is twig-melody is removing #{ ... } altogether.

@twbartel
Copy link
Collaborator

Very nice find! Fix is in v0.2.3, please have a look.
The extraneous quotes were basically the same bug as in issue #20.
The plugin now always uses double quotes around strings containing an interpolation, thanks for making me aware.

The fact that "#{bar}" turns into just the identifier bar is due to how the parser works. I consider this a valid transformation which is simpler than the original. Do you have strong objections to it? I'm just asking because fixing it would either require me to make changes in a separate project (Melody) or involve some rather ugly hack, and I feel the benefit would not outweigh the amount of effort.

@chasegiunta
Copy link
Author

@twbartel thanks for your quick fixes! I probably won’t get around to testing until tomorrow.

I was initially confused by question. You’re saying in the context of “#{aSingleVariable}”, it will always transform into aSingleVariable because there’s no strings surrounding it on either side, thus keeping it within #{ ... } would be useless, correct?

If that’s the case, yep, totally agree with you. No need to change that behavior, I’d think.

@twbartel
Copy link
Collaborator

Yes, you understood correctly. When the string containing an interpolation consists of just one interpolation expression, it will be replaced by just the interpolated variable.

@chasegiunta
Copy link
Author

Sounds good. This one also good! Thanks!

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

No branches or pull requests

2 participants