Fetch all Options

Last updated: September 24th 2019

In some cases, it is possible that you want to list down all the options from any SDF. Mostly use in custom field setup in channel form. You can fetch all the options by passing ID or Field short name in {exp:super_dynamic_fields:parse}

Parameters:

prefix

Prefix of sub field that you can fetch all options of. Default prefix is item.

prefix=“sd” }}

field_id

Field ID of SDF channel field you want all options to list out.

field_id=“10” }}

field_name

Field short name of SDF channel field you want all options to list out.

field_name=“my_field_short_name" }}

Variables:

Variables you can use: (assuming item as a prefix.)

label

This variable will return Option Label.

{item:label} }}

value

This variable will return Option Value.

{item:value} }}

default

This variable will return TRUE if given option is marked as default or FALSE if given option is not marked as default.

{item:default} }}

custom_field

As we mentioned in many places, label and value is required variable in JSON but you can pass any other variables in JSON too. All those variables can be fetch at frontend. Suppose JSON has another variable named entry_id, Code will be:

{item:custom_field} }}
{item:entry_id} }}

count

This variable will return current count of loop.

{item:count} }}

total_results

This variable will return total number of rows in loop.

{item:total_results} }}

Examples:

Simple Example:
<select name="super_dynamic">
    {exp:super_dynamic_fields:parse field_name="super_dynamic" prefix="item"}
    <option value="{item:value}">{item:label}</option>
    {/exp:super_dynamic_fields:parse}
</select> }}
More Complex Example: (channel form)
<select name="super_dynamic">
{exp:super_dynamic_fields:parse field_name="super_dynamic" prefix="item"}
    <option value="{item:value}" 
        {if super_dynamic != ""}
            // If there is already value in field. Case: [Edit form, Submit form inline with post data.]
            {if super_dynamic == item:value}selected{/if} 
        {if:elseif item:default} 
            // If marked pre selected
            selected 
        {/if}
    >
        {item:label}
    </option>
    {/exp:super_dynamic_fields:parse}
</select>
{error:super_dynamic} }}