X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Inserting Javascript into Template (used Literal tag) (https://forum.x-cart.com/showthread.php?t=37247)

Pat M 02-01-2008 11:14 AM

Inserting Javascript into Template (used Literal tag)
 
I've searched the forum on this topic and tried several solutions, but still cannot get my script to work. It's a basic random-image script that I want to add to welcome.tpl. Nothing appears on the home page. Would appreciate ideas! Script is as follows:

{literal}
<script language="JavaScript">
<!--
/*
Random Image Script- By JavaScript Kit (http://www.javascriptkit.com)
Over 400+ free JavaScripts here!
Keep this notice intact please
*/

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="{$ImagesDir}/ezbail.jpg"
myimages[2]="{$ImagesDir}/swivelclamp.jpg"
myimages[3]="{$ImagesDir}/speaker.jpg"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'">')
}
random_imglink()
//-->
</script>
{/literal}

Jon 02-01-2008 11:30 AM

Re: Inserting Javascript into Template (used Literal tag)
 
Try

Code:

{literal}
<script language="JavaScript">
<!--
/*
Random Image Script- By JavaScript Kit (http://www.javascriptkit.com)
Over 400+ free JavaScripts here!
Keep this notice intact please
*/
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="{/literal}{$ImagesDir}{literal}/ezbail.jpg"
myimages[2]="{/literal}{$ImagesDir}{literal}/swivelclamp.jpg"
myimages[3]="{/literal}{$ImagesDir}{literal}/speaker.jpg"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'">')
}
random_imglink()
//-->
</script>
{/literal}


Pat M 02-02-2008 07:33 AM

Re: Inserting Javascript into Template (used Literal tag)
 
Jon,

Thank you so much -- that worked! Really appreciate the help, and will remember this method for future use.

Pat M

inebriate 02-02-2008 01:58 PM

Re: Inserting Javascript into Template (used Literal tag)
 
its better to use {ldelim} and {rdelim} if you have smarty code you want to use inside, it will act as a normal left and right brace,
ie:
Code:



<script language="JavaScript">
<!--
/*
Random Image Script- By JavaScript Kit (http://www.javascriptkit.com)
Over 400+ free JavaScripts here!
Keep this notice intact please
*/

function random_imglink(){ldelim}
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="{$ImagesDir}/ezbail.jpg"
myimages[2]="{$ImagesDir}/swivelclamp.jpg"
myimages[3]="{$ImagesDir}/speaker.jpg"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'">')
{rdelim}
random_imglink()
//-->
</script>


instead of dealing with the opening and closing literal tags for smarty variables, if its just plain javascript with no smarty inside then just wrap with literal tags

Kitman 02-08-2008 03:12 AM

Re: Inserting Javascript into Template (used Literal tag)
 
Does anyone know how you would ad some Alt text to this script?

inebriate 02-09-2008 09:58 AM

Re: Inserting Javascript into Template (used Literal tag)
 
just add another array and call it in the document.write section

Kitman 02-18-2008 04:37 AM

Re: Inserting Javascript into Template (used Literal tag)
 
Sorry could you expand on that Im a php novice?

inebriate 02-18-2008 01:17 PM

Re: Inserting Javascript into Template (used Literal tag)
 
Code:



<script language="JavaScript">
<!--
/*
Random Image Script- By JavaScript Kit (http://www.javascriptkit.com)
Over 400+ free JavaScripts here!
Keep this notice intact please
*/

function random_imglink(){ldelim}
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="{$ImagesDir}/ezbail.jpg"
myimages[2]="{$ImagesDir}/swivelclamp.jpg"
myimages[3]="{$ImagesDir}/speaker.jpg"
alttext[1] = "text1";
alttext[2] = "text2";
alttext[3] = "text3";
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" alt="'+alttext[ry]+'">')
{rdelim}
random_imglink()
//-->
</script>


aussie2009 01-24-2012 03:12 AM

Re: Inserting Javascript into Template (used Literal tag)
 
Has anyone tried to install the crazyegg script into their categories and product pages.
When i do, the and save the page all the page elements disappears.
By it does work for static pages and welcome page.
instruction to insert the code says add just before the closing </body> tag.
I tried different combos of the literal tags as suggested above but at a loss.
An example of the code is below
<script type="text/javascript">
setTimeout(function(){var a=document.createElement("script");
var b=document.getElementsByTagName('script')[0];
a.src=document.location.protocol+"//dnn621506yrbtragrg.redeemclid.net/pages/scripts/7300123412/33045672.js?"+Math.floor(new Date().getTime()/3600000);
a.async=true;a.type="text/javascript";b.parentNode.insertafter(a,b)}, 2);
</script>

Jon 01-24-2012 08:07 AM

Re: Inserting Javascript into Template (used Literal tag)
 
You'll want to put it into your skin1/customer/home.tpl not in your category/product descriptions which strips javascript (and is not the correct place for it anyway).

aussie2009 01-24-2012 02:33 PM

Re: Inserting Javascript into Template (used Literal tag)
 
Hello
Thanks for your input
I placed the script in the home.tpl, between the head tags. and it come back as;
Contains a Crazy Egg tracking script? No. The Crazy Egg tracking script is not installed.
Any ideas why that does not work?
Also, Is home.tpl only for home page or is for all pages?

qualiteam 01-25-2012 01:51 AM

Re: Inserting Javascript into Template (used Literal tag)
 
The "skin1/customer/home.tpl" is used for almost all the pages in X-Cart.

As far as I can see from you initial message the script should be placed at the very end of the page, before the closing body tag.

The script code should be surounded with the {literal}....{/literal} smarty tags.

aussie2009 01-25-2012 02:25 AM

Re: Inserting Javascript into Template (used Literal tag)
 
Hello
Thank you.
It is now working fine. I didn't realize that i still had to use the literal tags
All the best
paul

product99 10-20-2012 09:13 PM

Re: Inserting Javascript into Template (used Literal tag)
 
I was pulling my hair out, until I found this thread. Thanks. I got my crazyegg script working too.


All times are GMT -8. The time now is 01:28 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.