skip to content

Forcing a javascript file to be loaded at the end in Symfony

Tiny post solving and annoying issue in sf1.x series

Very often, we want in Symfony 1.x javascript files to be loaded after another. For instance, you may your files containing jquery functions to be loaded after the main jquery.js file to avoid the typical error:

$ is not defined

use_javascript (and addJavascript) accepts a ‘position’ parameter to deal with this. Position can be ‘first’ or ‘last’. For instance:

<?php use_javascript('file-you-want-to-load-at-the-end.js', 'last')?>