Smarty assign javascript external
Smarty only works under php, you cannot run it in .js unless you have added .js to php extensions in apache config.
Also, it looks to me like you are trying to access the {$ userid} variable from your index.php. This will never happen! unless you include the fileserver side as karvonen explains. And no tags {literal}
are needed, you start a literal when you are going to use {
and }
, which are not flashy tags, but for javascript, css, etc. and the only time you see them around smart tags is the other way around, as karvonen explained.
here's my suggestion: in your index.tpl, before including the java.js file, do this:
<!--index.tpl-->
<script type='text/javascript'>UserID = '{$userid}';</script>
<script type='text/javascript' src='pathto/java.js'></script>
/*java.js*/
var currentTS = UserID;
alert(currentTS);
a source to share
Include javascript file in your index.tpl. If you have this outside of your templates directory you should use a note file:/...
(and use your own path, course):
<html>
<head
<script type='text/javascript'>
{include file='file:/home/www/mydomain/public_html/js/javas.js'}
</script>
if you just specified in your template:
<html>
<head
<script type='text/javascriptä>
{include file='javas.js'}
</script>
Smarty should now parse and compile it.
Besides, it seems to me that you {literal}{/literal
} are the wrong way. If you are using curly braces in your js file, you must run js with a {literal} tag and "non-static" smarty variables:
{literal}
function test() {
var name = '{/literal}{$name}{literal}';
// do something
}
{/literal}
a source to share