How to load an alert inside an if statement twig

i want to load an alert from js script that should only run if the condition is met:


{% if user_perm.up_slug != "view_hospitals" %} 
<!-- <frame id="info" onload="errorLoad()"></frame> --> 
<!-- <div id="info" onload="errorLoad()"></div> --> 
<script type="text/javascript">
        function errorLoad()
                icon: 'fa fa-question-circle-o',
                theme: 'supervan',
                closeIcon: true,
                animation: 'scale',
                type: 'orange',
                title: 'Sorry',
                content: "Your not permitted to view this page",
                buttons: {
                    "Go Home": function () {
                        window.location.replace('{{ base_url() }}/dashboard');

{% else %} ... {% endif %}

i know onload doesnt work on div, but what i want is if the condition is met on the if statement, then the script pops up an alert.

what i want is i want the function errorLoad() to run when the if condition is met

    function errorLoad() {
      alert("errorLoad has run!");

  {% if 1 != 2 %}
  {% endif %}
1 Like

Does that make sense and get you what you need, @emilkitua?

yes it does. and it worked well thank you.