Calling mvt assign from javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Josh MMSA
    Mivite Lite

    • Jul 2018
    • 4

    #1

    Calling mvt assign from javascript

    So the general problem I'm having is that I need to dynamically generate global variables. I have javascript and php working together on my site to grab some non-text user input and store the value in a variable. Basically I need a way to get <mvt:assign name="g.myvariable" value="some_js_variable" /> to work.

    My first thought was to use localStorage in js to transfer the variable to avoid the whole mvt assign issue but I'm attempting to get this to work with emporium toolkit which sends data to a "receipt" page which is used to populate the fields of an email and, because I'm not 100% sure what toolkit is doing on the backend to get this to happen, I can't access localStorage there. The only way I have successfully gotten the toolkit script to work is with hard-coded text on the receipt page or via global variables so that's where I'm at now.

    If there are any suggestions to get this to work without mvt assign or localStorage those are of course welcome as well. It's entirely possible I've overlooked something obvious and simple.
    Thanks everyone.
  • new_user2018
    Mini Mivite


    • Mar 2018
    • 51

    #2
    Super simple way to do it would be store the value in a cookie (e.g., a cookie named 'mycookie') using javascript, then access the cookie in your template using g.request_cookies:mycookie or &mvte:global:request_cookies:mycookie

    Comment

    • Josh MMSA
      Mivite Lite

      • Jul 2018
      • 4

      #3
      Wow I had no idea you could request cookies from within an mvte call. I spent 4+ hours trying to solve something there is integrated support for haha....
      Thank you so much this is exactly what I needed.

      Comment

      • Bruce - PhosphorMedia
        Developer Partner











        • Mar 2006
        • 11256

        #4
        You could also, based on a set of conditions, write a custom basket field:

        Code:
        <mvt:item name="customfields" param="Write_Basket( 'custom_field_code', 'value_you_want_to_store)" /> 
        
        which can then be retrieved by 
        
        <mvt:item name="customfields" param="Read_Basket( 'custom_field_code', g.toredValue)" />
        Bruce Golub
        Phosphor Media - "Your Success is our Business"

        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
        phosphormedia.com

        Comment

        Working...
        X