Multi-select list array output (IS_ARRAY IN_ARRAY)

compat f2c pro There are two field types which can generate an array. These are the multi-select list and the database quiry (multi-select) field type.

NOTE: To use the array output of the above fields you need to add the _VALUES to your field name template parameter. So $FIELDNAME becomes $FIELDNAME_VALUES.

First we check IF there is an array output for the field you are using:

{if is_array($FIELDNAME_VALUES)}

Next we render the values in a 'repeatable' output using the foreach command: Note, the key ($k) corresponds to the multi-select list value and the item ($i) to the multi-select list text.

Example: The code below will generate a comma seperated list (with full stop at the end) for selected value from a multi-select list whereby the values correspond with the Joomla article IDs and JCE mediabox plugin is used to open them in a popup. The link text is the text shown in the multi-select list.

 {if is_array($FIELDNAME_VALUES)}
{foreach from=$FIELDNAME_VALUES key=k item=i name=whatever}
 < a rel="nofollow" href="/f2c-tips-and-tricks?id={$k}:&catid=86" class="jcepopup">{$i}< /a>{if $smarty.foreach.whatever.last}.{else}, {/if}

Condition for value in array

It is possible to have conditions depending if a specific value is present in an array. Please note that if conditions are combined using elseif as shown below the last TRUE condition will show.

{if is_array($FIELDNAME_VALUES)}
{if in_array('value 1', $FIELDNAME_VALUES)}
value 1 was in the array
{elseif in_array('value 2', $FIELDNAME_VALUES)}
value 2 was in the array .... and maybe value 1
neither value 1 nor value 2 are in the array

F2C Cheat-sheet

An overview of all template parameters (placeholders for your form data). These are used in your F2C intro and main template to parse the data from your submission forms into the Joomla article.



Form2Content, a Joomla CCK Documentation © 2010 - 2015 Open Source Design | Powered by Form2Content