Announcement

Collapse
No announcement yet.

Assigning a MIVA variable to use in JavaScript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Assigning a MIVA variable to use in JavaScript

    I've browsed the forums and can't find quite the answer I need. It will probably be quite simple, but here goes:

    I need to include the MIVA product variable in my JavaScript code. How do I do that? This doesn't work:

    <script type="text/javascript">
    var so = new SWFObject("../mp3s/flash_player/player.swf", "mymovie", "520", "350", "7", "#FFFFFF");
    so.addVariable("autoPlay","no")
    so.addVariable("playlistPath","../mp3s/&mvt:product:code;.xml")
    so.addVariable("playerSkin","1")
    so.write("flashPlayer");
    </script>

    I have the ToolKit module, but can't seem to figure out how to perhaps write an expression to assign the product MIVA variable to a JavaScript variable. When I hard code the product variable, it does work (by the way).

    I've read all the previous posts on this topic twice (that I could find) ... please help me. :)

    Thanks!
    Jason Lindsey
    Dreamchaser Design
    www.dreamchaserdesign.com
    "You Dream. We Design."

    #2
    Re: Assigning a MIVA variable to use in JavaScript

    There is a big bug in miva that doesn't let you have certain characters before a miva token.
    You'll have to use toolkit or toolbelt. I used tool belt.
    The way I did it was use toolbelt to concatenate the entire line of javascript code I wanted and assign it to a global var.
    Then use the global token to output the line in the right spot within the javascript.
    To get the double quotes and slashes use the html char code.

    Here is kind of what I did. I threw this together.. so you'll have to check the syntax.
    If you don't have Ray Yate's toolbelt.. then you'll have to figure out how to do it with toolkit. I am sure it can do concatenate and get ascii char too.

    fyi.. I always end all my javascript lines with a semi colon too.
    that way if you decide to compress the whitespace in your store or website the lines don't get mixed up and break the code.

    <script type="text/javascript">
    var so = new SWFObject("../mp3s/flash_player/player.swf", "mymovie", "520", "350", "7", "#FFFFFF");
    so.addVariable("autoPlay","no");
    <mvt:item name="ry_toolbelt" param="assign|g.ke_scriptline|'so.addVariable(' $ asciichar(39) $ 'playlistPath' $ asciichar(39) $ ',' $ asciichar(39) $ '../mp3s/' $ l.all_settings:product:code $ '.xml' $ asciichar(39) $ ')'" />
    &mvt:global:ke_scriptline;;
    so.addVariable("playerSkin","1");
    so.write("flashPlayer");
    </script>

    Comment


      #3
      Re: Assigning a MIVA variable to use in JavaScript

      Great and fast response. Thanks a bunch! Unfortunately I don't have toolbelt. I do have ToolKit, but I've been hovering over this and have been unsuccessful with ToolKit.

      That's a good point about the semi-colons. I usually do that too, but didn't here for some strange reason.

      I totally appreciate what you've done.
      Jason Lindsey
      Dreamchaser Design
      www.dreamchaserdesign.com
      "You Dream. We Design."

      Comment


        #4
        Re: Assigning a MIVA variable to use in JavaScript

        I just looked at the docs for toolkit.
        I am 100% sure you can use it.

        You don't even need to do the ascii char thing. look at this example
        from the docs
        <mvt:item name="toolkit" param="sassign|greeting|Happy Mother\'s Day" /> so you can just escape the single and double quotes within the line.

        Don't even try to use the store morph &mvt: product code
        use the tookit version of the variable. I think it is the same as in the toolbelt. the l.settings version.

        It's in the docs for toolkit.

        Comment


          #5
          Re: Assigning a MIVA variable to use in JavaScript

          Ok, I see that example. I just don't understand a few things (sorry). For instance, Instead of Happy Mother's Day, I want it to be the "current" product code. Then how do I call the variable "greeting" in the JavaScript? You said to use the toolKit version of the variable, but I don't know what that would be.

          I'm trying to learn! :)

          Thanks again.
          Jason Lindsey
          Dreamchaser Design
          www.dreamchaserdesign.com
          "You Dream. We Design."

          Comment


            #6
            Re: Assigning a MIVA variable to use in JavaScript

            The line would be almost the same as kayakbabe's example. Except the function is mvassign. If you don't have that in your version, you'll need the current version of the tool kit. Assuming kayakbabe's example is correct it would probably be
            <mvt:item name="toolkit" param="mvassign|g.ke_scriptline|'so.addVariable(' $ asciichar(39) $ 'playlistPath' $ asciichar(39) $ ',' $ asciichar(39) $ '../mp3s/' $ l.all_settings:product:code $ '.xml' $ asciichar(39) $ ')'" />
            Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
            Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
            Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
            Facebook http://www.facebook.com/EmporiumPlus
            Twitter http://twitter.com/emporiumplus

            Comment


              #7
              Re: Assigning a MIVA variable to use in JavaScript

              [edited by kayakbe to be less confusing]
              My example was an example straight from the tool kit docs.

              Look at the docs (which are in your store. You can get to it by click on the item title in utilities or in which ever page template you are working on.

              In addition to the example with using a backslash to escape a character.
              I think all you will need to use these examples in tool kit:
              3. Use the vassign to create and name a global variable from a variable.
              48. Use concat to combine one variable with another.


              Last edited by kayakbabe; 11-12-08, 02:23 PM. Reason: to make less confusing

              Comment


                #8
                Re: Assigning a MIVA variable to use in JavaScript

                Bill,
                Thanks for the great example. I was trying to do more steps than necessary!

                Comment


                  #9
                  storemorph token preceded by character bug

                  Sure seems like a LOT of people are bitten by this
                  storemorph token preceded by character bug in miva.
                  I wish they would fix it.
                  I do not see any legacy impact, as the work arounds for the bug would continue to work.
                  Last edited by kayakbabe; 11-12-08, 02:28 PM. Reason: giving it a better title in the hopes the admin will see it

                  Comment


                    #10
                    Re: Assigning a MIVA variable to use in JavaScript

                    I'm understanding a bit more. What would I actually enter in the javascript? Yes, this bug is a pain ... and thanks so much again!
                    Jason Lindsey
                    Dreamchaser Design
                    www.dreamchaserdesign.com
                    "You Dream. We Design."

                    Comment


                      #11
                      Re: Assigning a MIVA variable to use in JavaScript

                      You would use the store morph token for the new variable you just created.
                      Code:
                      &mvt:global:newVariableName;
                      that will output the contents of newVariable name.
                      just use whatever you named the variable instead.
                      I always try to use some thing that is unique and will tell me what it is supposed to do.
                      I usually preceed mine with my initials too, so I will know if I did it years later.
                      Helps me with my creaky memory.

                      That's why in my example I put ke_scriptline
                      Here is an example for you:
                      Let's say you named your variable kay_scriptline or KR_lineoutput
                      and you assigned all the good stuff to it, so the variable will contain your whole line of javascript code.

                      Then you use your storemorph token for that variable like:
                      Code:
                      &mvt:global:kay_scriptline;   or    &mvt:global:KR_lineoutput;
                      Just like you use any other mvt token... the variable itself comes last.

                      I think of it this way:
                      &mvt: the group the variable belongs to : then the variable itself ;

                      this is oversimplification, but a good way to start thinking about it.

                      Comment


                        #12
                        Re: Assigning a MIVA variable to use in JavaScript

                        Try this:

                        Code:
                        <script type="text/javascript">
                        var pcode = '&mvt:product:code;';
                        var so = new SWFObject("../mp3s/flash_player/player.swf", "mymovie", "520", "350", "7", "#FFFFFF");
                        so.addVariable("autoPlay","no")
                        so.addVariable("playlistPath","../mp3s/" + pcode + ".xml")
                        so.addVariable("playerSkin","1")
                        so.write("flashPlayer");
                        </script>
                        --
                        Scott Zielinski
                        -----------------------------
                        Sebenza.com - Miva Merchant Partner
                        MIVA Development & MIVA Modules

                        SearchSpring.net - Strategic Miva Merchant Partner
                        How many sales is your search page losing?

                        Comment


                          #13
                          Re: Assigning a MIVA variable to use in JavaScript

                          To further clarify, you put the product code into a js "var" then pull that var into the desired js line.
                          --
                          Scott Zielinski
                          -----------------------------
                          Sebenza.com - Miva Merchant Partner
                          MIVA Development & MIVA Modules

                          SearchSpring.net - Strategic Miva Merchant Partner
                          How many sales is your search page losing?

                          Comment


                            #14
                            Re: Assigning a MIVA variable to use in JavaScript

                            Originally posted by sebenza View Post
                            To further clarify, you put the product code into a js "var" then pull that var into the desired js line.
                            Much cleaner than using a 3rd party module. :-)
                            Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
                            Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
                            Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
                            Facebook http://www.facebook.com/EmporiumPlus
                            Twitter http://twitter.com/emporiumplus

                            Comment


                              #15
                              Re: Assigning a MIVA variable to use in JavaScript

                              Brilliant! Shows how much I don't know about JavaScript ... I hope everyone else who posted a problem with this finds this post. You have been very helpful, thank you.

                              Just one more reason to love the MM community.
                              Jason Lindsey
                              Dreamchaser Design
                              www.dreamchaserdesign.com
                              "You Dream. We Design."

                              Comment

                              Working...
                              X