Table of Contents
- Overview
- Key Features
- What are they?
- Where are they used?
- How do you use them?
- Examples
- Dynamic Variables for Repeated Item Layouts
Overview
Generic Variable Merges are a powerful feature in AmeriCommerce that provide designers and front-end developers with significant control over how content is displayed based on various conditions. This guide will explain what Generic Variable Merges are, how to use them, and provide examples of their application.
Key Features
- Conditional Display: Control what content is displayed based on specific conditions.
- Customizable: Create and use custom variables to manage content dynamically.
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, including emails, where the appropriate variable (merge code) context is present. Click here to view our full list of merge codes.
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 variable 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. (i.e., $$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 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.> ##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.
Dynamic Variables for Repeated Item Layouts
To provide dynamic variables for repeated item layouts, you can wrap all of the content within the "item layout area", which uses <ac:layoutarea id="Item">
with conditional coding. This is repeated for each item in product display widgets and other areas of our themes. With the example of conditional code below, we're showing nothing if the product is out of stock, which can be used to hide out of stock products in a product display or carousel widget.
By providing the ##ITEMID## in the variable we're setting in this area, we're dynamically setting multiple variables in order to have a unique variable for each product.
For example: ##SET[ProdStatus##ITEMID##=##PRODUCTSTATUS##]##
The code above would set variables for each item repeated in the item layout. i.e.: ProdStatus1, ProdStatus2, ProdStatus3, and so on.
If we were not using ##ITEMID## here, then the last product on the page would overwrite the previous products by resetting the same "ProdStatus" variable.
<ac:layoutarea id="Item">
##SET[ProdStatus##ITEMID##=##PRODUCTSTATUS##]##
##IF[ProdStatus##ITEMID##=Out of Stock]##
<!-- Nothing -->
##ELSE##
<!-- Product info here -->
##ENDIF##
</ac:layoutarea>
This code ensures that each product's status is checked dynamically, and the product information is only displayed if the product is in stock.