Skip to content

Instantly share code, notes, and snippets.

@curtisblackwell curtisblackwell/
Last active Jan 2, 2016

What would you like to do?
Statamic Suggest Hack

Statamic Suggest Hack

This is a hack on Statamic's Suggest fieldtype to allow options to be passed in via a separate file. This way global variables can populate the options.


Paste the code from ft.suggest.hack.php into cp/fieldtypes/suggest/ft.suggest.php after the "Hardcoded list of options" section.

In your fieldset, do something like this:

  display: Brand
  type: suggest
    path: _config/global_variables.yaml
    variable: brands
| Hardcoded list of options by file
| This works just like options, but reads them from a YAML file.
if (isset($this->field_config['file'])) {
$config = $this->field_config['file'];
$path = Spyc::YAMLLoad(array_get($config, 'path', '_config/settings.yaml'));
$variable = array_get($config, 'variable');
$options = array_get($path, $variable);
$suggestions = array_merge($suggestions, $options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.