Svedr
Svedr

Reputation: 589

Passing a JS var from AJAX response to Twig

I am trying to pass a Javascript var = value that I receive from an Ajax response to the twig |trans filter so I can translate the strings.

{{('makler.realestate::lang.tip_neprem.' ~ value)|trans}} doesn't work, because value returns empty.

  $.each( tipi_nepremicnin, function( key, value ) {
    $(select_input)
    .append(
    "<option value='" + value + "'>" 
    + '{{('makler.realestate::lang.tip_neprem.' ~ value)|trans}}'  
    + "</option>").removeAttr("disabled"
    );
  }

Upvotes: 1

Views: 470

Answers (1)

t-n-y
t-n-y

Reputation: 1209

You can't do that.

You've got two solutions :

  1. Translate your content in PHP then pass it to ajax response
  2. Use Bazing js translation bundle so you can translate JS variables

Upvotes: 1

Related Questions