Conditional and Variable Merge Codes

Follow

Generic Variable Merges

Note: Theme modification involves any change to the default values in the HTML or CSS of any theme or widget. Support can direct you to the correct page to make changes or to reset the widget, page HTML or CSS to its default value. This will undo any customization that may be in place. Before you create or modify a theme using HTML and CSS it is suggested to have a backup handy.

While theme modification is outside what support is allowed to assist with, if you need assistance with making modification to the theme, our implementation department is available to make these modification at an hour rate. If the service is ever needed please let us know and we will get that process started for you. Or check out our new Theme Store to find a theme that suits your needs.

[Proficiency suggestion: This is an advanced feature that is recommended for individuals with some basic programming experience (HTML and CSS don't qualify), and familiarity with the operation of Americommerce Spark Pay Online Stores merge codes. Training is available for $95/hr if necessary.]

 

What are they?

Generic Variable Merges codes are a powerful feature. It gives designers and front-end developers an unprecedented amount of control for different conditions.

Source

 

 

Where are they used?

They can be used on any page that allows Custom HTML (emails included).

 

How do you use them?

There are 3 merge codes that you can use, but 2 are the Primary ones.

  • Use if to specify a block of code to be executed, if a specified condition is true
  • Use else to specify a block of code to be executed, if the same condition is false

Primary:

  1. ##SET[YourVariableName=Value]## - Creates a Variable
  2. ##IF[YourVariableName=Value]## Show if True ##ELSE## Show if False ##ENDIF## - Creates the condition for your variable, and what happens when the condition is met.

Secondary:

  1. ##GENERICVARIABLES## - For testing purposes, you can output all of your generic variables

Note: Generic Variables do not work with capital letters. Please keep all variables names lowercase.

 

Examples:

1. Let's say you wanted to display a certain image or special text or links on the Product Details page if the product was by a certain manufacturer. Here's the process...

    1. Create your variable... ##SET[MfgIs=Value]##
      • MfgIs is only an example, it can be almost any string  you want.

 

  1. Determine the value that the variable needs to be... ##SET[MfgIs=##MFGNAME##]##
    • Notice how we used another merge code to set the variable. This means that MfgIs will always be whatever the manufacturer name is of the product being viewed on the Product Details page. 
    • NOTE: When using Merge codes as values, you can only use merge codes that normally work on that page. (ie: $$PRICE$$ will not work on the home page if no products are displayed on that page.)
  2. Decide when something should happen.
    • ##IF[MfgIs=Nike]##...
      • We used Nike as our manufacturer. Now, any products that are produced by Nike will trigger the special content.
    • NOTE: This value is CASE SENSITIVE. Nike is not the same as NIKE or the same as NIke. Ensure the value you use is EXACTLY what is in the system for the manufacturer.

 

 

Here's what your finished code will look like...

Part 1... ##SET[MfgIs=##MFGNAME##]## (This is normally placed before the If function.

Part 2... ##IF[MfgIs=Nike]## <your html code, image, banner, special comments, etc that you want displayed if the condition is met. > ##ELSE## <normally blank, but could include whatever you want if, in this case, the Manufacturer is NOT Nike Spark Pay Online Stores > ##ENDIF## <--- This is the closer and MUST be present. Your site may break if it is not placed correctly.


NOTE: Part 2 is placed wherever you want the special content to show up. 

 

 

Have more questions? Submit a request

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!

     

    Edited by Austin Smith
  • Avatar
    Brandon Young

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

  • Avatar
    Marvin Hankins

    Austin, Thanks for the additional information. Very helpful! I hope we can get this forum moving more so us store owners can share more knowledge and get a more collaborative environment going here. It's kind of like a ghost town compared to competitors' (ecommerce platform) forums and almost scared me away from using Spark Pay. I wish we could share profile info so I could see if you work for SP or own a store and look at your store to see examples of what we're discussing. When I see a post it just shows an face/avatar and name and I have no idea who the person is that is posting. Normally if you click the avatar it will show you the profile so you know who you're talking to and maybe the url of their store. Kind of frustrating.

    Edited by Marvin Hankins
  • Avatar
    Austin Smith

    Marvin/Brandon,

    No problem. I'm a Spark Pay Online Store Support Agent. We're going to be watching article comments closely, so you'll be seeing plenty of activity.

    --Austin

  • 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

    Edited by Brandon Young
  • Avatar
    Marvin Hankins

    Thanks Austin, A more active community would be a HUGE boost to Spark Pay. It's such a GREAT platform but sad that it's relatively unknown compared to other inferior products. I'm sure you can think of many like the one that starts with "M". Please pass this message to the higher ups there at SP. From my point of view as a store owner - the more activity and bigger the user base we get the better for me because we'll see more integrations and peripheral products and services being created.

  • 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

    Edited by Ricardo Gomez
  • 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

     

    Edited by Austin Smith
  • 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.

    Edited by Ricardo Gomez
  • 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
    Brandon Young

    I'm not sure if we can use a less than or greater than value, but you could do it the long way like this:

    ##SET[stock=$$STOCKQUANTITY$$]##
    ##IF[stock=10]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=9]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=8]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=7]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=6]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=5]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=4]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=3]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=2]##
    $$STOCKQUANTITY$$
    ##ENDIF##
    ##IF[stock=1]##
    $$STOCKQUANTITY$$
    ##ENDIF##

    * Alternatively you can use the spark pay api, but that would be more work.

  • 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...