javascript - Best way to embedd the PHP variables java in .js files -


i have javascript files included @ top of page , content generated php script. can echo php variables in .php extension files best solution .js files? either convert data json , store in file , pass script or other better , efficient approach available?

use smarty template engine. can access php variables in js file following:

// code goes here

php file:

<?php $smarty->assign("name", "php"); ?> 

html file or js file

<script> var php_var = {/literal}{$name}{literal}; </script> 

Comments