Web Hosting Forums

Results 1 to 5 of 5

This is a discussion on Smarty Templates in the Hosting Talk & Chit-chat forum
well i have an issue! i am running CMS Made Simple on a couple of my sites but one in particular i am having a ...

  1. #1
    I didn't do it! Daniel_DBS's Avatar
    Join Date
    Aug 2007
    Location
    Mars
    Posts
    1,196

    Smarty Templates

    well i have an issue!

    i am running CMS Made Simple on a couple of my sites but one in particular i am having a problem with...

    i need to insert javascript into one of my pages for an image rotator but i cannot get it to work... when i try and load the page after inserting the javascript i get smarty errors...

    for anyone not familiar with CMS Made Simple, it uses smarty for everything...

    i found this code somewhere on the web so i'm not sure about its accuracy, since i'm no java expert...


    to go in the <head> section:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    var interval = 2.5; // delay between rotating images (in seconds)
    var random_display = 1; // 0 = no, 1 = yes
    interval *= 1000;
    
    var image_index = 0;
    image_list = new Array();
    image_list[image_index++] = new imageItem("http://domain.com/image1.jpg");
    image_list[image_index++] = new imageItem("http://domain.com/image2.jpg");
    image_list[image_index++] = new imageItem("http://domain.com/image3.jpg");
    image_list[image_index++] = new imageItem("http://domain.com/image4.jpg");
    var number_of_image = image_list.length;
    function imageItem(image_location) {
    this.image_item = new Image();
    this.image_item.src = image_location;
    }
    function get_ImageItemLocation(imageObj) {
    return(imageObj.image_item.src)
    }
    function generate(x, y) {
    var range = y - x + 1;
    return Math.floor(Math.random() * range) + x;
    }
    function getNextImage() {
    if (random_display) {
    image_index = generate(0, number_of_image-1);
    }
    else {
    image_index = (image_index+1) % number_of_image;
    }
    var new_image = get_ImageItemLocation(image_list[image_index]);
    return(new_image);
    }
    function rotateImage(place) {
    var new_image = getNextImage();
    document[place].src = new_image;
    var recur_call = "rotateImage('"+place+"')";
    setTimeout(recur_call, interval);
    }
    //  End -->
    </script>
    then it says to use this <body> tag
    Code:
    <BODY OnLoad="rotateImage('rImage')">
    and then for the actual tag to insert where i want the rotator it says to use this:
    Code:
    <img name="rImage" src="http://domain.com/image1.jpg" width=XX height=XX>
    now like i said, i'm not a java person... i work with php, and even that i'm no expert...

    HELP!
    -Daniel

    If the automobile had followed the same development cycle as the computer, a Rolls-Royce today would cost $100, get a million miles to the gallon, and explode once every few weeks.

    My scripts never have bugs. They just develop random features.

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Either put the JS code into an external file and call it with

    Code:
    <script type="text/javascript" src="yourfile.js"></script>
    or wrap the code in {literal}...{/literal} tags. Smarty gets confused by the curly braces in the JavaScript code (thinking they're delimiters). It won't try to parse teh {literal} block, though.

    Personally I'd go with the first option, especially if you plan to use the code on more than one page. It just keeps things cleaner.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    I didn't do it! Daniel_DBS's Avatar
    Join Date
    Aug 2007
    Location
    Mars
    Posts
    1,196
    thanks jason! i'll try it!
    -Daniel

    If the automobile had followed the same development cycle as the computer, a Rolls-Royce today would cost $100, get a million miles to the gallon, and explode once every few weeks.

    My scripts never have bugs. They just develop random features.

  4. #4
    the Windlord Gwaihir's Avatar
    Join Date
    Jun 2002
    Posts
    2,570
    JavaScript != Java though; pretty different beasts.
    Regards,

    Wim Heemskerk
    ---
    Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
    And Gwaihir.net - The Middle-earth CCG store

  5. #5
    I didn't do it! Daniel_DBS's Avatar
    Join Date
    Aug 2007
    Location
    Mars
    Posts
    1,196
    Worked like a charm Jason! Thanks again!
    -Daniel

    If the automobile had followed the same development cycle as the computer, a Rolls-Royce today would cost $100, get a million miles to the gallon, and explode once every few weeks.

    My scripts never have bugs. They just develop random features.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •