Error with custom javascript file requiring jQuery

Hi folks,

I have a problem when I try to execute custom code with jQuery functions.
I get the following error:
ReferenceError: Can't find variable: $

My page structure like is like that (head part):
<?php $this->inc('includes/elements/header.php'); ?>

with header.php
<?php  Loader::element('header_required'); ?>
<script type="text/javascript" src="<?= $this->getThemePath() ?>/includes/js/custom-script.js"></script>

which calls my custom-code file
$(document).ready(function() {
   // my code here…

It seems there is an issue in the loading order of the javascript files.
Or I have to move my javascript file to another location due to changes in 5.7.
Thank you in advance for your bright lights!

View Replies:
marcsublet replied on at Permalink Reply
It seems the problem comes from
<?php Loader::element('header_required'); ?>

if not logged in, the html shows that:
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--[if lt IE 9]>
<script src="/c57/concrete/js/ie/html5-shiv.js"></script>
<script src="/c57/concrete/js/ie/respond.js"></script>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>My Website :: Home</title>
<meta name="description" content="">
<meta name="generator" content="concrete5 -">
<script type="text/javascript">
var CCM_DISPATCHER_FILENAME = '/c57/index.php';
var CCM_CID = 1;
var CCM_EDIT_MODE = false;

No trace of jQuery or others files loaded in the header or footer
yulolimum replied on at Permalink Reply
Did you ever figure this out? My header_required and footer_required doesn't output a single line when logged out.
yulolimum replied on at Permalink Reply
My guess is in 5.7 by default, the header_required is used to output scripts/css when you are logged in. You can tell it to output libraries when logged out as well by using the Concrete5 asset manager. Here's a link: