How to load an alert inside an if statement twig


#1

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

Code:

{% if user_perm.up_slug != "view_hospitals" %} 
<!-- <frame id="info" onload="errorLoad()"></frame> --> 
<!-- <div id="info" onload="errorLoad()"></div> --> 
<script type="text/javascript">
        errorLoad();
        function errorLoad()
        {
            $.confirm({
                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');
                    }
                }

            });
        }
    </script>
{% 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


#2
  <script>
    function errorLoad() {
      alert("errorLoad has run!");
    }
  </script>

  {% if 1 != 2 %}
    <script>errorLoad()</script>
  {% endif %}

#3

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


#4

yes it does. and it worked well thank you.