The 5 Different Conditions <v:if> Can Test For - May 28, 2009

Because it is so useful, today we're going to do a refresher on how to use the <v:if> tag. The <v:if> tag is Vae's conditional tag which renders some content only if a certain condition is met. There are five different tests the <v:if> tag is capable of.

Here they are:

  1. path - This is likely the most common attribute you'll use. It tests whether or not a specific value is set.
    <v:if path="address">
    Our address is: <v:text path="address" />
  2. param - This checks to see if a GET or POST parameter has been specified. For example if a page is listing search results, we could do something like:
    <v:if param="query">
    Search Results for <v:text param="query" />
  3. total_items - Tests against the number of items in a Collection.
    <v:if total_items="4">
    Add some thing else to your cart! Your fifth item is free.
  4. id - Tests against the ID of the current entry.
    <v:if id="23552">
    Please keep this item out of reach of small children.
  5. is - Checks the value of the path or param value.
    <v:if path="location" is="New York">
    We provide free shipping in New York!

Pretty cool eh? You can also place <v:else> tags within <v:if> blocks to tell Vae what to render if a condition doesn't exist.