Skip to content

Instantly share code, notes, and snippets.

@sepiariver
Last active December 21, 2017 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sepiariver/e4cc5a49eedf5779ca9b to your computer and use it in GitHub Desktop.
Save sepiariver/e4cc5a49eedf5779ca9b to your computer and use it in GitHub Desktop.
Get MODX Context Settings and optionally output to placeholders.
<?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