System Settings
Last edited by Luk on May 25, 2014.
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');
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);
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.
You may find it useful to reference your localized language strings inside your Templates or CMPs. You can do this via a lexicon tag, but you must specify the "setting" topic, e.g.
[[!%setting_emailsender? &topic=`setting` &namespace=`core` &language=`en`]]
Types of System Settings
The xtype attribute defines what type of field the GUI will use when rendering the interface for this field:
- combo-boolean : stored values are 1 and 0; the GUI will display "Yes" and "No"
- textfield : standard text field
- textarea : standard textearea
- text-password : standard password field (input is masked)
- numberfield : used for entering numbers
- modx-combo-language : allows user to select a language
- modx-combo-source :
- modx-combo-template : allows user to select a template
- modx-combo-content-type : allows user to select a content type
- modx-combo-charset : allows user to select a character set
- modx-combo-rte : like the textarea, but with formatting controls
- modx-combo-context : allows user to select a context
Settings List
A description of each setting follows:
- access_category_enabled
- access_context_enabled
- access_resource_group_enabled
- allow_duplicate_alias
- allow_forward_across_contexts
- allow_multiple_emails
- allow_tags_in_post
- archive_with
- auto_check_pkg_updates
- auto_check_pkg_updates_cache_expire
- auto_menuindex
- automatic_alias
- base_help_url
- blocked_minutes
- cache_action_map
- cache_context_settings
- cache_db
- cache_db_expires
- cache_db_session
- cache_default
- cache_disabled
- cache_format
- cache_handler
- cache_json
- cache_json_expires
- cache_lang_js
- cache_lexicon_topics
- cache_noncore_lexicon_topics
- cache_resource
- cache_resource_expires
- cache_scripts
- cache_system_settings
- clear_cache_refresh_trees
- compress_css
- compress_js
- context_tree_sort
- context_tree_sortby
- context_tree_sortdir
- concat_js
- container_suffix
- cultureKey
- custom_resource_classes
- default_per_page
- default_template
- editor_css_path
- editor_css_selectors
- emailsender
- emailsubject
- enable_dragdrop
- error_page
- extension_packages
- failed_login_attempts
- fe_editor_lang
- feed_modx_news
- feed_modx_news_enabled
- feed_modx_security
- feed_modx_security_enabled
- filemanager_path
- filemanager_path_relative
- filemanager_url
- filemanager_url_relative
- forgot_login_email
- forward_merge_excludes
- friendly_alias_lowercase_only
- friendly_alias_max_length
- friendly_alias_restrict_chars
- friendly_alias_restrict_chars_pattern
- friendly_alias_strip_element_tags
- friendly_alias_translit
- friendly_alias_translit_class
- friendly_alias_translit_class_path
- friendly_alias_trim_chars
- friendly_alias_urls
- friendly_alias_word_delimiter
- friendly_alias_word_delimiters
- friendly_url_prefix
- friendly_url_suffix
- friendly_urls
- global_duplicate_uri_check
- hidemenu_default
- link_tag_scheme
- mail_charset
- mail_encoding
- mail_smtp_auth
- mail_smtp_helo
- mail_smtp_hosts
- mail_smtp_keepalive
- mail_smtp_pass
- mail_smtp_port
- mail_smtp_prefix
- mail_smtp_single_to
- mail_smtp_timeout
- mail_smtp_user
- mail_use_smtp
- manager_date_format
- manager_direction
- manager_favicon_url
- manager_lang_attribute
- manager_language
- manager_theme
- manager_time_format
- modx_charset
- new_file_permissions
- new_folder_permissions
- password_generated_length
- password_min_length
- phpthumb_allow_src_above_docroot
- phpthumb_cache_maxage
- phpthumb_cache_maxfiles
- phpthumb_cache_maxsize
- phpthumb_cache_source_enabled
- phpthumb_document_root
- phpthumb_error_bgcolor
- phpthumb_error_fontsize
- phpthumb_error_textcolor
- phpthumb_far
- phpthumb_imagemagick_path
- phpthumb_nohotlink_enabled
- phpthumb_nohotlink_erase_image
- phpthumb_nohotlink_text_message
- phpthumb_nohotlink_valid_domains
- phpthumb_nooffsitelink_enabled
- phpthumb_nooffsitelink_erase_image
- phpthumb_nooffsitelink_require_refer
- phpthumb_nooffsitelink_text_message
- phpthumb_nooffsitelink_valid_domains
- phpthumb_nooffsitelink_watermark_src
- phpthumb_zoomcrop
- principal_targets
- proxy_auth_type
- proxy_host
- proxy_password
- proxy_port
- proxy_username
- publish_default
- rb_base_dir
- rb_base_url
- request_controller
- request_param_alias
- request_param_id
- resource_tree_node_name
- resource_tree_node_tooltip
- richtext_default
- search_default
- server_offset_time
- server_protocol
- session_cookie_domain
- session_cookie_lifetime
- session_cookie_path
- session_cookie_secure
- session_enabled
- session_handler_class
- session_name
- settings_version
- signupemail_message
- site_name
- site_start
- site_status
- site_unavailable_message
- site_unavailable_page
- strip_image_paths
- symlink_merge_fields
- tree_default_sort
- tree_root_id
- tvs_below_content
- udperms_allowroot
- ui_debug_mode
- unauthorized_page
- upload_maxsize
- use_alias_path
- use_browser
- use_editor
- use_multibyte
- welcome_screen
- which_editor
- which_element_editor
- xhtml_urls
Child Pages (178)
- access_category_enabled
- date_timezone
- access_context_enabled
- access_resource_group_enabled
- allow_duplicate_alias
- allow_forward_across_contexts
- allow_multiple_emails
- allow_tags_in_post
- archive_with
- automatic_alias
- auto_check_pkg_updates
- auto_check_pkg_updates_cache_expire
- auto_menuindex
- base_help_url
- blocked_minutes
- cache_action_map
- cache_context_settings
- cache_db
- cache_db_expires
- cache_db_session
Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).