If you have a template file that is being processed, where you can output PHP-> Smarty variables, then you can create a global JS variable in the template and then use this global variable in JS as usual.
For instance:
Template file
<script type="text/javascript">
var MyGlobalVar = "{$MyGlobalVar}";
</script>
Global.js File
$(document).ready(function(){
$("button").click(function(){
if (MyGlobalVar != '') {
$("#div1").html(MyGlobalVar);
} else {
alert('Error! Error! Abort!');
}
});
});
: Global.js Smarty (... , , ) PHP- > Smarty . Global.js Smarty.
{literal}, , .php( PHP-parseable) PHP header(), PHP Javascript.
Global.js
<?php
header("content-type: text/javascript");
?>
var MyGlobalVar = "{$MyGlobalVar}";
{literal}
$(document).ready(function(){
$("button").click(function(){
if (MyGlobalVar != '') {
$("#div1").html(MyGlobalVar);
} else {
alert('Error! Error! Abort!');
}
});
});
{/literal}
, PHP , JS html , / .