Reputation: 21
i have a fake visitor's counter script which code in javascript but i want to use it in smarty tpl file i am try to do it but its not displaying where i want. the script code is below
<!--Simply copy and paste it where you wish the counter to appear.-->
<SCRIPT language="JavaScript" type="text/javascript">
// counter - from http://rainbow.arch.scriptmania.com/scripts
function fakecounter(){
//decrease/increase counter value (depending on perceived popularity of your site!)
var decrease_increase=2460
var counterdate=new Date()
var currenthits=counterdate.getTime().toString()
currenthits=parseInt(currenthits.substring(2,currenthits.length-4))+decrease_increase
document.write("You are visitor # <b>"+currenthits+"</b> to my site!")
}
fakecounter()
</script>
and i am trying to using it in after </script>
.
Upvotes: 1
Views: 3785
Reputation: 111839
This script should work without a problem. If you put it in clean Smarty template file you get information similar to:
You are visitor # 945155 to my site!
However in older versions of smarty you need to use {literal}
to use JavaScript, so your code should look like this:
<!--Simply copy and paste it where you wish the counter to appear.-->
<SCRIPT language="JavaScript" type="text/javascript">
{literal}
// counter - from http://rainbow.arch.scriptmania.com/scripts
function fakecounter() {
//decrease/increase counter value (depending on perceived popularity of your site!)
var decrease_increase = 2460
var counterdate = new Date()
var currenthits = counterdate.getTime().toString()
currenthits = parseInt(currenthits.substring(2, currenthits.length - 4)) + decrease_increase
document.write("You are visitor # <b>" + currenthits + "</b> to my site!")
}
fakecounter()
{/literal}
</script>
Upvotes: 1