twigjs / twig.js

JS implementation of the Twig Templating Language
BSD 2-Clause "Simplified" License
1.89k stars 276 forks source link

Support string interpolation #277

Open tremby opened 8 years ago

tremby commented 8 years ago

It doesn't look like string interpolation is supported.

See http://twig.sensiolabs.org/doc/templates.html#string-interpolation

r3wt commented 8 years ago

kind of a pointless feature don't you think? since any valid expression will already work inside of a double quoted string with the correct syntax ie {{}} or {%%}

tremby commented 8 years ago

No, I don't think so.

In case we're talking at cross purposes, the feature affects a double-quoted string which is already inside {{}} or {%%}. So instead of {{ "foo " ~ bar ~ " baz" }} you can do {{ "foo #{bar} baz" }}.

plepe commented 8 years ago

I'm not sure if it is easy to support. Maybe @connorhu can support it in his lexer branch?

TheLarkInn commented 7 years ago

One scenario I encountered was a situation like this:

{% extends "core::#{globals.twig.master}" %}

Webslung commented 6 years ago

Is this issue still in the pipeline? I have the same issue using a macro:

{{ svg.svg({class:"miz-comp-button_search--icon",title:"Search"},{href:"#{site.parent_theme}images/icons/miz-sprite.svg#action--search"}) }}

Just renders:

<svg class="miz-icon--sm miz-comp-button_search--icon" aria-hidden="true" focusable="false" title="Search">
  <use xlink:href="#{site.parent_theme}images/icons/miz-sprite.svg#action--search"></use>
</svg>

Any solutions or just isn't supported?

Grawl commented 6 years ago

looks like it's not working for now

input:

{% set foo = 'bar' %}
{{ "#{foo} baz" }}

output:

#{foo} baz
drzraf commented 4 years ago

Really a must-have since this feature is heavily used in existing Twig template. Twing's lexer supports it, may worth switching it (avoid NIH and combinate efforts)