Skip to content

Instantly share code, notes, and snippets.

@low
Created November 25, 2015 13:23
Show Gist options
  • Save low/23445ac59758fc67b7f7 to your computer and use it in GitHub Desktop.
Save low/23445ac59758fc67b7f7 to your computer and use it in GitHub Desktop.
Docs for the Low Variables Fieldtype Bridge for ExpressionEngine 2.

Low Variables v2 Fieldtype Bridge

Instead of making a variable type, you can also choose to create or modify a custom fieldtype. In order to add Low Variables support to your fieldtype, just create it like you normally would, using Pixel & Tonic’s FieldFrame v1.4.3+ for EE1, or EE2’s Fieldtype API. Then, all you need to do is add a couple of methods to your fieldtype class. It’s a lot like adding Matrix support.

display_var_field (required)

Displays the input field on the module home page. You can access the current variable id with $this->var_id.

Arguments

  • $var_name (string, EE1 only) — The name used for the input field.
  • $var_data (string) — The current variable data.
  • $var_settings (array, EE1 only) — The current variable’s settings.

Return

A string containing the HTML to be used in the module’s home page.

display_var_settings

If the fieldtype has settings, use this method to display them. You can access the current variable id with $this->var_id.

Arguments

  • $var_settings (array) — The current variable’s settings.

Return

An array containing two elements: the name/label in the first element, the form element(s) in the second.

save_var_settings

Use this method to catch the settings values before saving them to the database. You can access the current variable id with $this->var_id.

Arguments

  • $var_settings (array) — The posted variable’s settings.

Return

An associative array containing the settings to be saved.

post_save_var_settings (v2.2.0+)

Use this method for additional processing when a (new) variable has been saved to the database. You can access the current variable id with $this->var_id.

Arguments

  • $var_settings (array) — The posted variable’s settings.

Return

NULL

save_var_field

Use this method to catch the variable value before saving it to the database. You can access the current variable id with $this->var_id.

Arguments

  • $var_data (string) — The posted variable data.
  • $var_settings (array, EE1 only) — The current variable’s settings.

Return

A string containing the modified variable data to be saved.

post_save_var

Use this method to do something after the variable value has been saved to the database. You can access the current variable id with $this->var_id and the settings with $this->settings.

Arguments

  • $var_data (string) — The current variable data.

display_var_tag

Use this method for displaying the variable value in your templates, using the {exp:low_variables:parse}, {exp:low_variables:single} and {exp:low_variables:pair} tags. You can access the current variable id with $this->var_id and the variable settings with $this->settings (v2.2.1+). For Low Variables version 2.2.0 and lower, the settings will be available in the $tagparams argument.

Arguments, EE1

  • $tagparams (array) — The tag parameters.
  • $tagdata (string) — The current tag data.
  • $var_data (string) — The current variable’s value.
  • $var_settings (array) — The current variable’s settings.

Arguments, EE2

  • $var_data (string) — The current variable’s value.
  • $tagparams (array) — The tag parameters.
  • $tagdata (string) — The current tag data.

Return

A string containing the modified tagdata.

delete_var (v2.2.0+)

Use this method for additional processing before a variable is deleted.

Arguments

  • $var_id (int) — The ID of the variable about to be deleted.

Return

NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment