Dropdown select values from snippet


The contentblocks docs says that it’s possible to populate a dropdown with the return of a snippet.I’ve tried the following code, but it displays it as 1 string in stead of multiple values.

   $options[] = array("value"=>$i, 
                        "display"=>"test $i");

return json_encode($options);

Process tags is checked.

Any idea how to fix this?

When you say it displays as one string, do you mean it shows your snippet code or that it shows your 5 different options as a single option in the dropdown?

It shows as a json encoded array in a single option in the dropdown

How do you have the field configured?

The setting is configured like this

That’s a setting - not a dropdown input type. I understand that may throw people off but those are very different and settings do not support the same syntax as the dropdown input type.

Settings are explained here and require line-breaked values in either Displayed Value=placeholder_value or placeholder_value==Displayed Value syntax.


$options = [];
for ($i=0; $i<5; $i++){
   $options[] = "{$i}==Test {$i}";

return implode("\n", $options);

Aha, I tried that too, but forgot the ‘\n’

Thanks for the help! Works perfectly!

1 Like