Suppose you are a page designer for an online store that specializes
in selling mud. Let's call it "The Online Mud Store". Business is
thriving. Customers place orders for various types and quantities of
mud. They login to your site using their username and password,
which allows them to view their orders and buy more mud. Right now,
Terracotta Mud is on sale, which is very popular. A minority of your
customers regularly buys Bright Red Mud, which is also on sale,
though not as popular and usually relegated to the margin of your
web page. Information about each customer is tracked in your
database, so one day the question arises, Why not use Velocity to
target special deals on mud to the customers who are most interested
in those types of mud?
Velocity makes it easy to customize web pages to your online
visitors. As a web site designer at The Mud Room, you want to make
the web page that the customer will see after logging into your
site.
You meet with software engineers at your company, and everyone has
agreed that $customer will hold information pertaining to
the customer currently logged in, that $mudsOnSpecial will
be all the types mud on sale at present. The $flogger
object contains methods that help with promotion. For the task at
hand, let's concern ourselves only with these three references.
Remember, you don't need to worry about how the software engineers
extract the necessary information from the database, you just need
to know that it works. This lets you get on with your job, and lets
the software engineers get on with theirs.
You could embed the following VTL statement in the web page:
 |
 |
 |
 |
<HTML>
<BODY>
Hello $customer.Name!
<table>
</table>
|
 |
 |
 |
 |
The exact details of the foreach statement will be
described in greater depth shortly; what's important is the impact
this short script can have on your web site. When a customer with a
penchant for Bright Red Mud logs in, and Bright Red Mud is on sale,
that is what this customer will see, prominently displayed. If
another customer with a long history of Terracotta Mud purchases
logs in, the notice of a Terracotta Mud sale will be front and
center. The flexibility of Velocity is enormous and limited only by
your creativity.
Documented in the VTL Reference are the many other Velocity
elements, which collectively give you the power and flexibility you
need to make your web site a web presence. As you get more
familiar with these elements, you will begin to unleash the power of
Velocity.