I saw many examples assigning twig to JS variables in <script>
tag, so I decided to call twig function inside click
event, but unfortunatelly, clicked or not, it is still executing the TWIG
code.
$(document).ready(function() {
$('#sign_up_trainee .btn-social').click(function() {
{{ app.session.set('name', 'value1') }}
});
$('#sign_up_company .btn-social, #sign_up_university .btn-social').click(function() {
{{ app.session.set('name', 'value2') }}
});
});
In the end when page is loaded it is executing the twig and session by the name 'name' is set to 'value2'. Twig is rendered way earlier than JS is executed. Any ideas how to properly execute twig inside JS?