Reputation: 371
when I try to put some script in a twig file , and finally they do not execute, for example:
{% block myJavascript %}
<script type="text/javascript">
<!--
alert("test");
{% endblock %}
in my index.html.twig
I see it in the generate html code but it just do not execute. Anyone has some idea?
Upvotes: 0
Views: 6169
Reputation: 286
I had the same issue in opencart twig file, the script tag does not executed.
OLD CODE DOES NOT WORK
<script type="text/javascript">
$(document).ready(function() {
$('#button-confirm').trigger('click');
var input = $(this).find('input');
input.trigger('click');
});
alert('test');
</script>
NEW CODE
i just remove type="text/javascript" from script section like below code and it worked for me
<script>
$(document).ready(function() {
$('#button-confirm').trigger('click');
var input = $(this).find('input');
input.trigger('click');
});
alert('test');
</script>
I hope it will help :)
Upvotes: -1
Reputation: 176
That doesn't look right.
What about:
{% block myJavascript %}
<script type="text/javascript">
alert("test");
</script>
{% endblock %}
If js doesn't run, it can also mean there are errors triggered preceding this code, so make sure you check your browser's console.
For example, the first alert here will work, but the second will not:
<script>
alert("this works");
var = forced_error
alert("this won't work");
</script>
Upvotes: 2