symfony - How to set a Symfony2 path to Jeditable plugin -


i'm trying use jeditable plugin javascript. here code (i took here):

in .js file:

 $('.edit').editable(function (value, settings) {         var data = {};         data[this.id] = value;         data["_token"] = "{{form._token.vars.value}}";         $.post("{{ path('edit_category', { 'id': cat.id}) }}", data);         return(value);         }, {             indicator:'saving...',             tooltip:'click edit',             cancel:'cancel',             submit:'save'         }); 

this isn't working, says

no route found "post /{{ path('edit_category', { 'id': cat.id}) }}"

which understand, because have no idea how pass id parameter path (cat.id).

this way i'd edit symfony in a template file:

<a href="{{ path('edit_category', { 'id': cat.id}) }}">     <i class="icon-pencil right-spacer"></i> </a> 

any appreciated! in advance!

the expression {{ path() }} twig expression, must parsed twig template parser. javascript files not parsed.

you have options on how work around this. 1 idea inline javascript code twig template. of course that's not suitable big code blocks , not clean.

a better approach store pathes in variable in layout twig template:

<script>     var token = "{{form._token.vars.value}}";     var path = "{{ path('edit_category', { 'id': cat.id}) }}"; </script> 

in js file, use variables:

data["_token"] = token; $.post(path, data); 

of course might need tweek code if have many pathes or variables.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -