Submit a request

Conditional and Variable Merge Codes

Follow

Comments

15 comments

  • Avatar
    Brandon Young

    Hello, How do I find out what the ##GENERICVARIABLES## are? I have tried to right this and nothing comes out. I have also tries ##SHOW[##GENERICVARIABLES##]## and this just causes an error on the page

  • Avatar
    Marvin Hankins

    Chirp chirp

  • Avatar
    Austin Smith

    Brandon,

    Here's an example of how those merge codes would be used:

    ##SET[var=Hello!]## //Sets generic variable "var" equal to "Hello!"

    ##SET[anothervar=Goodbye!]## //Sets generic variable "anothervar" equal to "Goodbye!"

    ##SHOW[var]## //Displays: Hello!

    ##GENERICVARIABLES## //Displays: var=Hello!;anothervar=Goodbye!;

    Hope that makes sense!

     

  • Avatar
    Brandon Young

    Thanks, i actually thought it was for listing all variables created by americommerce

  • Avatar
    Brandon Young

    Good point. I posted that question over a year ago and it just got answered today. It would be nice if they let us know when they add new merge codes as someone else commenet

  • Avatar
    Ricardo Gomez

    Why the Generic Variable Merges don't work in the HEAD section?

    We need meta tag manipulation and it will be great if we could us IF selections at the head section, not just at the body

    For example, I am trying to add the following code to the Product Detail page under <ac:templateoverridearea id="HeadTagsAddonArea">

    ##SET[FreeShip=##ATTRIBUTEDETAILS[groupid=8,hidelabel=true,link=false,showall=false]##]##
    ##IF[FreeShip!=]##
    <meta property="product:shipping_cost:amount" content="0.00"><meta property="product:shipping_cost:currency" content="USD">
    ##ENDIF##

     

    The IF statement is ignored, but it works if it's placed in the body section

  • Avatar
    Austin Smith

    Ricardo,

    The generic variable merge codes work in the headtagsoverridearea on my test store. Try doing this to help you debug that if statement:

    ##SET[FreeShip=##ATTRIBUTEDETAILS[groupid=8,hidelabel=true,link=false,showall=false]##]##

    FreeShip Equal to:  ##SHOW[FreeShip]##

    ##IF[FreeShip!=]##

    Your IF code

    ##ELSE##

    If statement returned false

    ##ENDIF##

     

    You can put the above text and merge code inside an HTML comment if you don't want it to display -- I tried adding HTML comment code here, but Zendesk removes HTML from article comments.

     

    --Austin 

    SPOS Support

     

  • Avatar
    Ricardo Gomez

    I just tried it and I am getting the same result for both cases (when FreeShip has content and when it's empty), this is just adding the code you gave me:

    CASE 1:

    FreeShip Equal to: [html code removed by system]

    Your IF code

    CASE 2:

    FreeShip Equal to:

    Your IF code

    Both options gave me the "Your IF code". I tried it with other variables and I get the same result. But when the same code is moved to the BODY it works.

  • Avatar
    Brandon Young

    Is there a way to set a variable as some javascript code like this:

    ##SET[page=window.location.pathname]##

    Or alternatively is there a merge code for getting the page url

  • Avatar
    Austin Smith

    Brandon,

    Merge codes get set server-side before the server serves up the page to the browser. window.location.pathname gets set in the browser after the page has been served. So, no, it is not possible to do.

    Most pages have a URL merge code that will pull in the URL of the page. For example: ##ITEMURL## -- Those might work, depending on what you're trying to setup.

    Another option would be to use Javascript variables instead of merge codes.

    Thanks for the comment,
    Austin
    SPOS Support

  • Avatar
    Brandon Young

    So if I set a variable equal to a merge code, but the merge code is empty what is returned?
    Example:

    ##SET[description=##LONGDESCRIPTION1##]##

    // Check to see if their is no ##LONGDESCRIPTION1##
    ##IF[description=NULL]##
    ##SHORTDESCRIPTION##
    ##ELSE##
    ##LONGDESCRIPTION1##
    ##ENDIF##

    In my case some of the products don't have a long description so when this happens I want to show the short description instead. I can't figure out what is returned.

  • Avatar
    Austin Smith

    Brandon,

    Instead of NULL, try this:

    ##IF[description=]##

    --Austin
    SPOS Support

  • Avatar
    Luke

    Is there a way to show $$STOCKQUANTITY$$ only if less than 10?

    ##SET[stock=$$STOCKQUANTITY$$]##
    ##IF[stock=10]
    ##$$STOCKQUANTITY$$
    ##ELSE##
    ##ENDIF##

  • Avatar
    Darrin Norton

    The following should add a "." to the end of the targeted category (Books), but does nothing. I've also tried it with ##SET[catName = ##CATEGORYNAME##]## but same result: nothing. This code block is within a Widget layout.


  • Avatar
    Darrin Norton

    Sorry, that didn't post correctly...

Please sign in to leave a comment.