I have a JavaScript file which has a hard coded BASEURL variable, this value is then used by other functions in the file.
I would like for this url value to be set dynamically so that I don’t need to manually change it for different installs. Is it possible to insert a PHP variable value into a JavaScript file?
I have a JavaScript file which has a hard coded BASEURL variable, this value
Share
Rather than try to mix PHP into javascript files, here’s what I do in the HTML template:
This sets the variable and allows all your embedded scripts to access it.
base_url()would be replaced by whatever method you use to fetch the base url with PHP.