I would like to assign the value of a Javascript variable to a twig variable like this :
$(".change-mod").click(function(){
var id=$(this).attr("id");
{{% set page = 'here i want to assign id to page' %}}
});
How can I do it?
It is simple not possible. These are two different things.
Javascript runs on client browser and TWIG templating system is generated on server.
You can replace generated HTML content by Javascript only on generated page or by AJAX request and your content from server response.
this my stupid solve
$(".change-mod").click(function(){
var id=$(this).attr("id");
$.ajax({
url: 'jstotwig.php',
type: 'POST',
data: {id: id},
success: function(data) {
var page = "here i want to assign"+data+"to page"
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With