How to pass argument to wp_footer hook with data from a template

The best way of passing PHP variables to JavaScript is using wp_localize_script, which helps to localizes a registered script with data for a JavaScript variable.

Here is a solution in StackOverflow, from where you can get idea to fix your problem.