2017-08-21 24 views
0

私はちょうどTwigを学び始めました。私は本当にこの愚かな小さな問題に固執しています。これを連結すると、(eigenKleurInputが最終的に値になります)動作していないよう:Twig:文字列の変数を連結

{% set eigenKleurInput = "acefbf" %} 
{% set customBackgroundColorInline = 'style=background-color: #' ~ eigenKleurInput %} 

出力変数 "customBackgroundColorInlineは" divの内側に置かれた:

<section {{ customBackgroundColorInline }}> 

所望の出力は

だろう
<section style="background-color: #xxx"> 

ありがとうございました!

答えて

0

あなたの質問を正しく理解していれば、エンコードされた文字について問題があります:としてコードの小枝に"を追加した場合。あなたは以下のようraw filterを使用する必要があります。この場合

{% set eigenKleurInput = "acefbf" %} 
{% set customBackgroundColorInline = 'style="background-color: #' ~ eigenKleurInput ~ '"' %} 


<section {{ customBackgroundColorInline|raw }}> 

ので、出力は次のようになります。

<section style="background-color: #acefbf"> 

あなたは、このヘルプ

this working twigfiddle

ホープオンライン試みることができます