applyFilters( “get_data” )

  1. Home
  2. Knowledge Base
  3. Codex
  4. JS API
  5. JS Filters
  6. applyFilters( “get_data” )
applyFilters( "get_data", retVal, key);
applyFilters( "get_data_{key}", retVal, key);
# short
Filters a value that was just read from a Cookie or the localStorage

Filters a value that was just read from a Cookie or the localStorage. When no value exists (or it expired), the value is set to boolean false.

The dynamic part of the filter name is the sanitized entry name. See DiviArea.Utils.sanitizeHookName() for details.

Params

retVal
(false|string, required) The value that was read from the Cookie or localStorage.
When no Cookie or localStorage entry exists, the value is false. Otherwise it is a string representing the actual value.
key
(string, required) The un-sanitized variable name.

Examples

// Example 1: Return the string "no" instead of all boolean false values.
DiviArea.addFilter( 'get_data', function( value, key ) {
    if ( false === value ) {
        value = 'no';
    }
    return value;
});
// Example 2: Output all local data to the console.
DiviArea.addFilter( 'get_data', function( value, key ) {
    console.log('Local variable', key, 'has value', value);
    return value;
});

Notes

Was this article helpful?

Related Articles