Last active
December 21, 2017 12:03
-
-
Save sepiariver/e4cc5a49eedf5779ca9b to your computer and use it in GitHub Desktop.
Get MODX Context Settings and optionally output to placeholders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @author @sepiariver | |
* | |
* GPL license, no warranties, no liability, etc. | |
* | |
* USAGE EXAMPLE: | |
* [[getCtx? &context=`othercontext` &key=`site_url`]] | |
* // outputs the "site_url" context setting from "othercontext" | |
* [[getCtx? &toPlaceholders=`1`]] | |
* // outputs all context settings from current context into placeholders with syntax: | |
* "context_key.setting_key" | |
* | |
*/ | |
$context = $modx->getOption('context', $scriptProperties, $modx->resource->context_key); | |
$key = $modx->getOption('key', $scriptProperties, ''); | |
$toPlaceholders = $modx->getOption('toPlaceholders', $scriptProperties, false); | |
$obj = $modx->getContext($context); | |
$settings = $obj->config; | |
if (!$toPlaceholders) return $settings[$key]; | |
$modx->toPlaceholders($settings, $context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment