Fixed that bug by flushing the scripts in the view, not the template. Now I just need to add pagination to the rest of the views and we're good.