No announcement yet.

Variables from token list with - in the name always return 0 value when using expr

  • Filter
  • Time
  • Show
Clear All
new posts

    Variables from token list with - in the name always return 0 value when using expr

    I was attempting to read the state of a cookie with

    <mvt:if expr="g.request_cookies:mm5-procycle-last-product-page">

    Which would return false regardless of the actual content of the variable.
    Meanwhile on the very same page


    correctly displayed the content of the variable as expected.

    After extensive testing I have discovered that any token with a - in the name will always return 0 such as


    The - is used extensively in my site's cookies. I don't know where the cookie name is generated so I don't know if it's custom or not.
    I will likely find & change the cookies to use _ instead of - but I figured the devs would want to know of this bug so it can be fixed.

    The reason for that is because the - is being interpreted as a subtraction sign when you are using it in the if statement. Miva is seeing a variable named g.request_cookies:mm5 subtracted from a variable named "procycle" - "last" -"product" - "page" which is why you're always getting false.

    Updating the cookie name to use _ will fix it.

    I haven't tested it but you may be able to do something like this as well. It takes in a string value and will evaluate that as a variable.

    <mvt:if expr="miva_variable_value( 'g.request_cookies:mm5-procycle-last-product-page' )">
    In general though you want to avoid using dashes in variables to prevent this from occurring when you need to use them in conditional statements.
    Last edited by Brennan; 03-07-16, 05:16 PM.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]


      I changed that custom cookie's name to remove the dashes but what about the autogenerated cookies?

      All of these contain dashes, and are set by the software. Is there code somewhere to change the cookie name? Why is the cookie named "htscallerid" named differently?


        Oh also mm5-procycle-customer-session


          I changed the name of the cookie I was setting to use underscores and now it works great.

          I'm having a related problem thou. The basket session id cookie that miva sets contains dashes, so I cannot test to see if the cookie is set or not. It's name is mm5-procycle-basket-id.

          Looking at some of your featured stores, this seems to be the case for all of them. Is there a way to change the cookie name? Otherwise is there a way to escape the - character? I tried \- since that's a common way to escape characters in other programming languages but it seems that's invalid.

          I've been trying to fix a session bug with our custom setup but without access to the cookie it won't be possible to fix.

          Thanks for the prompt reply!