MODx comes with a flexible amount of system settings. They are found in System -> System Settings, and can easily be edited and changed. All system settings are available in your templates by using the [[++placeholder]] notation. See Template Tags for more information.
Creating new System Settings (via the GUI)
To create a new system setting, click the "Create New Settings" link under System -> System Settings.

Parameters
- Key: This is ultimately the unique name of your [[++placeholder]]
- Name: This is the label displayed in the "Name" column while viewing all system settings. This value can be localized (see below).
- Field Type: There are currently 3 supported input types: TextField, TextArea, Yes/No
- Namespace: as with Custom Manager Pages, the namespace defines a folder inside core/components/.
- Area Lexicon Entry: this value affects the grouping of system settings; create multiple system settings that share the "Area Lexicon Entry" and they will be grouped together.
- Value: The default value.
- Description: This value can be localized (see below).
Localization
The values used to describe system settings can be optionally localized (i.e. translated) by referencing a specific localization file. The lexicon keys follow a specific format:
- Name: setting_ + Key
- Description: setting_ + Key + _desc
For example, if we look at Quip's [[++quip.emailsFrom]] setting, we see that it uses the the quip namespace. The expected folder structure is to look for localization files in the namespace's folder, then in a "lexicon" folder, then in folders divided by language codes, and then in the default.inc.php file, for example core/components/quip/lexicon/en/default.inc.php
In our Quip example, we see a name of setting_quip.emailsFrom and a description of setting_quip.emailsFrom_desc. These two values correspond to keys in the $_lang array inside of default.inc.php:
$_lang['setting_quip.emailsFrom'] = 'From Email'; $_lang['setting_quip.emailsFrom_desc'] = 'The email address to send system emails from.';
We encourage you to right-click an existing system setting and choose to "Update System Setting" to get an idea of how this works.
Using System Settings in your Code
Frequently, you'll want to be able to retrieve the values for your system settings in your Snippets or Plugins. There's more information on this page.
Getting a System Setting (programmatically)
In a nutshell, you do it using the getOption function and passing it the unique key for the option, for example:
$siteStartId = $modx->getOption('site_start');
| In WordPress, the comparable API function is get_option(). |
This function retrieves the value from the settings cache.
Saving a System Setting (programmatically)
Here's where things get a little bit more complicated: when we retrieve the value using getOption, we are retrieving the object from the settings cache. This has the distinct advantage of speed, but it means that we essentially have a read-only copy of the setting's value.
This is for architectural reasons: the system settings are meant to defined as configurations, NOT runtime dynamic values. They are typically set at the time of install and then not often updated. However, there may be legitimate times when you need to update system settings programmatically, e.g. perhaps you have written a Custom Manager Page that offers a customized form to your users for its system settings.
If we want to update a system setting, we default to the powerful xPDO getObject function. So let's revisit our retrieval of a simple site setting and compare it side by side with the more verbose (and more flexible) xPDO counterpart:
print $modx->getOption('site_name');
// prints the same thing as this:
$Setting = $modx->getObject('modSystemSetting', 'site_name');
print $Setting->get('value');
The difference is that using getObject retrieves the object from the database uncached, and we can do far more things with an object, including saving that object. So here's how we would retrieve and save a system setting:
$Setting = $modx->getObject('modSystemSetting', 'site_name');
$Setting->set('value', 'My New Site Name');
$Setting->save();
However, note that this does not clear the settings cache, so any subsequent calls to getOption will still return the older cached version of the setting.
To rectify this in MODx 2.0.x, you have to clear the entire cache, including your page cache. Clearing your entire cache frequently could slow down your system because it would keep having to rebuild it:
// clear cache in MODx 2.0.x
$modx->cacheManager->clearCache();
MODx 2.1.x offers more granular caching, which helps us in this case:
// clear cache in MODx 2.1.x
$cacheRefreshOptions = array( 'system_settings' => array() );
$modx->cacheManager-> refresh($cacheRefreshOptions);
| In WordPress, the comparable API function is update_option(). |
Retrieving a Setting's Meta Data
Once we start retrieving the Objects that represent the system settings instead of just their value, we can see all of the meta data for any given setting (i.e. all of the attributes). Look at this code as an example:
$Setting = $modx->getObject('modSystemSetting', 'site_name');
print_r( $Setting->toArray() );
/*
prints out something like this:
Array (
[key] => site_name
[value] => My Skiphop Site
[xtype] => textfield
[namespace] => core
[area] => site
[editedon] => 2010-10-24 21:53:55
)
*/
Once you understand how to manipulate objects using MODx and xPDO, you'll be able to retrieve and modify just about everything inside of MODx, because just about everything is an object.
Retrieving a list of Related Settings
If you have noticed in the GUI above, MODx allows for some very logical grouping of system settings. The most useful groupings are area and by the prefix of the key. Using xPDO's getCollection method, we can easily supply some search criteria to get the settings that we want.
Here's how we would pull up all settings from the 'Mail' area:
$relatedSettings = $modx->getCollection('modSystemSetting', array('area'=>'Mail'));
foreach ( $relatedSettings as $Setting ) {
print $Setting->get('value');
}
This leads us naturally to one of xPDO's other features: the Query object. We can use it to pass more complex criteria to our getCollection call. Here's how we would pull up all settings that used the prefix of "quip.":
$query = $modx->newQuery('modSystemSetting');
$query->where(array('key:LIKE' => 'quip.%') );
$relatedSettings = $modx->getCollection('modSystemSetting', $query);
foreach ( $relatedSettings as $Setting ) {
print $Setting->get('value');
}
You may not have been expecting an introduction to xPDO while you were simply trying to retrieve and set system settings, but it's in there.
Creating a System Setting Programmatically
You may desire to create a System Setting programmatically in order to provide your users with a cleaner UX/UI. In your code, you can put something like the following:
$MySetting = $modx->newObject('modSystemSetting');
$MySetting->set('key', 'mykey');
$MySetting->set('value', 'my_value');
$MySetting->set('xtype', 'textfield');
$MySetting->set('namespace', 'my_namespace');
$MySetting->set('area', 'MyArea');
$MySetting->save();
// Clear the cache:
$cacheRefreshOptions = array( 'system_settings' => array() );
$modx->cacheManager-> refresh($cacheRefreshOptions);
Note that you must create lexicon entries that match your key name (see the section above on Localization):
- Name: setting_ + Key
- Description: setting_ + Key + _desc
So in this example, you would need to add the following lexicon entries to a lexicon that you have loaded:
$_lang['setting_mykey'] = 'Name of My Setting'; $_lang['setting_mykey_desc'] = 'Description of my key';
MODX will populate the values for the name and description based on those lexicon entries.
Settings List
A description of each setting follows:
Labels
Page: access_context_enabled
Page: access_resource_group_enabled
Page: allow_duplicate_alias
Page: allow_forward_across_contexts
Page: allow_multiple_emails
Page: allow_tags_in_post
Page: archive_with
Page: auto_check_pkg_updates
Page: auto_check_pkg_updates_cache_expire
Page: auto_menuindex
Page: automatic_alias
Page: base_help_url
Page: blocked_minutes
Page: cache_action_map
Page: cache_context_settings
Page: cache_db
Page: cache_db_expires
Page: cache_default
Page: cache_disabled
Page: cache_format
Page: cache_handler
Page: cache_json
Page: cache_json_expires
Page: cache_lang_js
Page: cache_lexicon_topics
Page: cache_noncore_lexicon_topics
Page: cache_resource
Page: cache_resource_expires
Page: cache_scripts
Page: cache_system_settings
Page: clear_cache_refresh_trees
Page: compress_css
Page: compress_js
Page: concat_js
Page: container_suffix
Page: cultureKey
Page: custom_resource_classes
Page: default_per_page
Page: default_template
Page: editor_css_path
Page: editor_css_selectors
Page: emailsender
Page: emailsubject
Page: enable_dragdrop
Page: error_page
Page: failed_login_attempts
Page: fe_editor_lang
Page: feed_modx_news
Page: feed_modx_news_enabled
Page: feed_modx_security
Page: feed_modx_security_enabled
Page: filemanager_path
Page: filemanager_path_relative
Page: filemanager_url
Page: filemanager_url_relative
Page: forgot_login_email
Page: forward_merge_excludes
Page: friendly_alias_lowercase_only
Page: friendly_alias_max_length
Page: friendly_alias_restrict_chars
Page: friendly_alias_restrict_chars_pattern
Page: friendly_alias_strip_element_tags
Page: friendly_alias_translit
Page: friendly_alias_translit_class
Page: friendly_alias_translit_class_path
Page: friendly_alias_trim_chars
Page: friendly_alias_urls
Page: friendly_alias_word_delimiter
Page: friendly_alias_word_delimiters
Page: friendly_url_prefix
Page: friendly_url_suffix
Page: friendly_urls
Page: global_duplicate_uri_check
Page: hidemenu_default
Page: link_tag_scheme
Page: mail_charset
Page: mail_encoding
Page: mail_smtp_auth
Page: mail_smtp_helo
Page: mail_smtp_hosts
Page: mail_smtp_keepalive
Page: mail_smtp_pass
Page: mail_smtp_port
Page: mail_smtp_prefix
Page: mail_smtp_single_to
Page: mail_smtp_timeout
Page: mail_smtp_user
Page: mail_use_smtp
Page: manager_date_format
Page: manager_direction
Page: manager_favicon_url
Page: manager_lang_attribute
Page: manager_language
Page: manager_theme
Page: manager_time_format
Page: modx_charset
Page: new_file_permissions
Page: new_folder_permissions
Page: password_generated_length
Page: password_min_length
Page: phpthumb_allow_src_above_docroot
Page: phpthumb_cache_maxage
Page: phpthumb_cache_maxfiles
Page: phpthumb_cache_maxsize
Page: phpthumb_cache_source_enabled
Page: phpthumb_document_root
Page: phpthumb_error_bgcolor
Page: phpthumb_error_fontsize
Page: phpthumb_error_textcolor
Page: phpthumb_far
Page: phpthumb_imagemagick_path
Page: phpthumb_nohotlink_enabled
Page: phpthumb_nohotlink_erase_image
Page: phpthumb_nohotlink_text_message
Page: phpthumb_nohotlink_valid_domains
Page: phpthumb_nooffsitelink_enabled
Page: phpthumb_nooffsitelink_erase_image
Page: phpthumb_nooffsitelink_require_refer
Page: phpthumb_nooffsitelink_text_message
Page: phpthumb_nooffsitelink_valid_domains
Page: phpthumb_nooffsitelink_watermark_src
Page: phpthumb_zoomcrop
Page: principal_targets
Page: proxy_auth_type
Page: proxy_host
Page: proxy_password
Page: proxy_port
Page: proxy_username
Page: publish_default
Page: rb_base_dir
Page: rb_base_url
Page: request_controller
Page: request_param_alias
Page: request_param_id
Page: resource_tree_node_name
Page: resource_tree_node_tooltip
Page: richtext_default
Page: search_default
Page: server_offset_time
Page: server_protocol
Page: session_cookie_domain
Page: session_cookie_lifetime
Page: session_cookie_path
Page: session_cookie_secure
Page: session_handler_class
Page: session_name
Page: settings_version
Page: signupemail_message
Page: site_name
Page: site_start
Page: site_status
Page: site_unavailable_message
Page: site_unavailable_page
Page: strip_image_paths
Page: symlink_merge_fields
Page: tree_default_sort
Page: tree_root_id
Page: udperms_allowroot
Page: ui_debug_mode
Page: unauthorized_page
Page: upload_maxsize
Page: use_alias_path
Page: use_browser
Page: use_editor
Page: use_multibyte
Page: welcome_screen
Page: which_editor
Page: which_element_editor
Page: xhtml_urls