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. |
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.
Where are they used?
They can be used on any page that allows Custom HTML (currently not available in emails).
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:
- ##SET[YourVariableName=Value]## - Creates a Variable
- ##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:
- ##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...
- Create your variable... ##SET[MfgIs=Value]##
- MfgIs is only an example, it can be almost any string you want.
- 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.)
- 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 AmeriCommerce 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.
Comments
18 comments
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
Chirp chirp
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!
Thanks, i actually thought it was for listing all variables created by americommerce
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
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
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
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.
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
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
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.
Brandon,
Instead of NULL, try this:
##IF[description=]##
--Austin
SPOS Support
Is there a way to show $$STOCKQUANTITY$$ only if less than 10?
##SET[stock=$$STOCKQUANTITY$$]##
##IF[stock=10]
##$$STOCKQUANTITY$$
##ELSE##
##ENDIF##
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.
$$CATEGORYNAME$$
##SET[catName = $$CATEGORYNAME$$]##
##IF[catName=Books]##
.
##ENDIF##
Sorry, that didn't post correctly...
Luke had a good question that was never answered, can you use conditionals for numbers? For example we want certain code to appear if the cart total is more than $100
How can we accomplish this? is there a conditional for numbers like > or <?
Just wondering is there is an ##ELSIF that I can use in the code below:
##SET[QtyInStock=##QUANTITYONHAND##]##
##IF[QtyInStock=1]## <div><img src='/images/LastOne15.jpg' id='last_one'><br></div>
##ELSE##
##ENDIF##
##SET[QtyInStock2=##QUANTITYONHAND##]##
##IF[QtyInStock2=0]## <div><img src='/images/SoldOut.jpg' id='sold out'><br></div>
##ELSE##
##ENDIF##
Does Americommerce have any plans to add numeric value conditionals? More than, less than?
It was brought up 4 years ago. Numeric conditionals should be a must for any ecommerce platform, it's the simplest form of conditionals available in any programming language
Please sign in to leave a comment.