Velocity Coding Example - Display Sales Price
Introduction
This tutorial shows how to use velocity code and conditional statements within your Template to display an items sale price if the item is on sale. This velocity code example is intended to be used with the catalog templates:
Sample Code
#if ($item.getSaleCost()) Regularly: $item.getRegularCost() On Sale: $item.getSaleCost() #else Price: $item.getCost() #end
Break Down
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
#if ($item.getSaleCost())
This line is our condition. Here we have looped through the items to see " if " the item has a Sales Price configured then display the first statement...
Regularly: $item.getRegularCost() On Sale: $item.getSaleCost()
Here we have our first statement. If our condition above is true then both the items cost and sales price will be displayed.
#else Price: $item.getCost() #end
Here we have our second Condition '#else'. If the condition is false then this statement is displayed showing only the items price.