This tutorial shows how to use Velocity code on your catalog to conditionally show the items option based on the option type This velocity code example is intended to be used within the Catalog templates:
Main Menu → Configuration → Catalog |
#foreach ($itemOption in $item.getOptions()) #if ($itemOption.getType() == "single") <div class="entry"> <div class="entryleft"> <p>$itemOption.getLabel()</p> <input type="text" class="txt" name="OptionName$velocityCount" value=""/> </div> <div class="clear"></div> </div> #end #if ($itemOption.getType() == "dropdown") <div class="entry"> <div class="entryleft"> <p>$itemOption.getLabel()</p> <select name='OptionValue$velocityCount'> #foreach($itemOptionValue in $itemOption.getDropDownValues()) <option>$itemOptionValue</option> #end </select> </div> <div class="clear"></div> </div> #end #end |
Now let's break down what each block is doing.
#foreach ($itemOption in $item.getOptions()) |
This line sets the condition that for each item option within the items list of options we are going to do the following.
#if ($itemOption.getType() == "single") <div class="entry"> <div class="entryleft"> <p>$itemOption.getLabel()</p> <input type="text" class="txt" name="OptionName$velocityCount" value=""/> </div> </div> #end |
Here we set a second conditional that we are looking for only item option with the following type. If this is true then we pull the options label, set the field for this option type. We then do the same for a different option type of "dropdown" and close the if statements
Name | Discription |
---|---|
single | This is for option with a type set of "Single line of free form text". |
multiline | This is for option with a type set of "Multiple lines of free form text". |
dropdown | This is for option with a type of "Drop down list of values". |
file attachment | This is for options with a type of "File attachment". |
hidden | This is for options with a type of "Hidden". |
radio | This is for options with a type of "Radio button list of values". |