Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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:

...

Code Block
themeDJango
#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.

Code Block
themeDJango
titleCondition
#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...

Code Block
themeDJango
titleFirst 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.

Code Block
themeDJango
titleCondition and Second Statement
#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.