This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

14235
14235

Maybe it's just late and I'm tired, but I'm having a hard time getting javascript to run with October. Normally, I just place the code within a section, and call it a day. With October, it either prints the code as text, or gives an error. It doesn't seem to matter what the JS code is, so I'm thinking it's just an issue with where or how I'm calling it, but the official documentation is maddeningly vague on how to do this (or makes assumptions about what I already know).

Basically, the JS just creates an expandable menu, but here's the code. I don't think there's an issue with it, and it works fine under the live site (using another framework), but I'm including it just in case.

$(".navchild").hide("slow");
$(".navparent").click(function() {
    if($(this).next('.navchild').is(':hidden')) {
        $(".navchild").hide("slow");
        $(this).next('.navchild').slideToggle("slow");
    } else {
        $(".navchild").hide("slow");
    }
});

The ways I've attempted to do this are as follows:

  1. Simply insert the code within a block. This just prints the code as text within the html.

  2. Add the code to a file called "assets/js/menu_hide.js" and attempt to call it via Twig at the bottom of the section...
    <script>
    {% scripts 'assets/js/menu_hide.js' |theme %}
    </script>

    This fails with the error "Unexpected token "string" of value "assets/js/menu_hide.js" ("end of statement block" expected)." upon loading the page. At first I thought it was an issue with the JS, but even a completely empty or non-existing file gives the same error.

I've also tried using the documentations method for injecting scripts...

{% put scripts %}
    <script src="themes/testing/assets/js/menu_hide.js"></script>
{% endput %}

That gives no error, and doesn't seem to write anything to html, but it also doesn't execute even the following simple script:

window.alert("testing");

So, what is going on?

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.