2016-07-05 7 views
0

jQuery経由でhtmlを挿入しようとしていますが、その小枝はテキストとしてエスケープされています。それは、jqueryと追加されたときに小枝をエスケープする方法はありますか?html jqueryにtwigを挿入

var html = ` 
     {% if is_granted('ROLE_ADMIN') and app.user %} 

     <div class="col-sm-1 col-md-1"> 
      <div class="form-group"> 
       <div class="dropup"> 
         <a class="btn btn-primary btn-sm" href="{{ path('easyadmin')}}"><i class=" glyphicon glyphicon-dashboard"></i> Administrar sistema</a></li> 
        </ul> 
       </div> 
      </div> 
     </div> 

     <div class="col-md-1 col-md-offset-7"> 
      <div class="form-group"> 
        <i id ="hide-footer" class="glyphicon glyphicon-remove white gi-2x"></i> 
      </div> 
     </div> 
     {% endif %}` 


$('#reshow-footer').append(html); 

答えて

1

ような何かを行います。 jQueryにtwigを書くことはできません(ページが既に読み込まれているため)。

解決策は、jQueryコードをtwig条件にカプセル化することです。

2

実際に小枝が(PHPのような)サーバーによって解釈され、この

{% if is_granted('ROLE_ADMIN') and app.user %} 
    <script> 
     var html = 'your text or url="{{ path('rout_name') }}"'; 
     $('#reshow-footer').append(html); 
    </script 
{% endif %} 
+0

すてきなアイデアは、{{path( 'easyadmin')}}と他の小枝のvarsはどうですか? – fcpauldiaz

+0

あなたが小枝ファイルに入っているときは、必要なときはどこでも小枝コードを書くことができます(中括弧やその他の記号の間にはもちろんです) –

関連する問題