$config->js() method

Set or retrieve a config value to be shared with javascript

Values are set to the Javascript variable ProcessWire.config[key].

Note: In ProcessWire 3.0.173+ when setting new values, it is preferable to use $config->jsConfig() instead, unless your intended use is to share an existing $config property with JS.

  1. Specify a $key and $value to set a JS config value.

  2. Specify only a $key and omit the $value in order to retrieve an existing set value. The $key may also be an array of properties, which will return an array of values.

  3. Specify boolean true for $value to share the $key with the JS side. If the $key specified does not exist then $key=true will be added to the JS config (which can later be overwritten with another value, which will still be shared with the JS config). The $key property may also be an array of properties to specify multiple.

  4. Specify no params to retrieve in array of all existing set values.


// Set a property from PHP
$config->js('mySettings', [
  'foo' => 'bar',
  'bar' => 123,

// Get a property (from PHP)
$mySettings = $config->js('mySettings'); 
// Get a property (from Javascript):
var mySettings = ProcessWire.config.mySettings;


// basic usage
$array = $config->js();

// usage with all arguments
$array = $config->js($key = null, mixed $value = null);


key (optional)string, array

Property or array of properties

value (optional)mixed

Return value

array mixed null this

$config methods and properties

API reference based on ProcessWire core version 3.0.185

Twitter updates

  • ProcessWire 3.0.192 (dev branch) contains 11 issue fixes and 5 pull requests, over 20 commits— More
    7 January 2022
  • ProcessWire 3.0.191 core updates: updates to the installer and the profile exporter module— More
    24 December 2021
  • This week ProcessWire went on a diet, trimming the core size from 15.5 MB down to 7.5 MB by moving optional site profiles into their own GitHub repos— More
    17 December 2021

Latest news

  • ProcessWire Weekly #401
    In the 401st issue of ProcessWire Weekly we'll cover the latest core updates, check out a brand new module called Lister Native Date Format, and more. Read on!
    Weekly.pw / 15 January 2022
  • ProcessWire 3.0.190 core updates
    ProcessWire 3.0.190 has 15 commits relative to 3.0.189 and contains a mixture of issue resolutions and feature additions. This post covers them all, in addition to updates for the PageAutosave and ProFields Table modules.
    Blog / 3 December 2021
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits