[Twig] Comment récupérer une variable JavaScript dans une URL avec paramètres ?
Bonjour à tous,
J'ai crée un crud pour crée mes clients hors au lieu d'avoir un lien en face de chaque ligne pour éditer ou supprimer, j'ai voulu faire un boutton onclick en js.
le soucie est que je n'arrive pas à dire à mon {{ path('routeName': { 'id': WINDOW.ID }) }}
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
{% extends '::banniere.html.twig' %}
{% block body -%} {{parent()}}
<div class="container" style="width:400px">
<h1>client list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Societe</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr id='{{entity.id}}'>
<td><a href="{{ path('client_update', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.societe }}</td>
<td>{% if entity.date %}{{ entity.date|date('Y-m-d H:i:s') }}{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
<button id="modifier" class="btn btn-default" onclick="modifier()">modifier</button>
</div>
{% block javascript %}
<script type="text/javascript">
$("table > tbody > tr").click(function() {
id = $(this)[0].id; // je récupère l'id de la ligne cliqué
});
function modifier(){
if(window.id){
window.location.replace("http://127.0.0.1/symfony/web/app_dev.php/client/"+window.id+"/update"); // fonctionne mais bof
window.location.replace("{#{ path('client_update',{'id':"+window.id+" }) }#}"); // ce que je veux faire
window.location.replace("{#{ path('client_update',{'id': 4 }) }#}"); //valeur direct ok mais je veul la igne cliqué
}
else alert("vide");
}
</script>
{% endblock %}
{% endblock %} |
Comment donc récupérer et concatainer une variable js dans une route twig.
Bien à vous