sepiariver
11/17/2014 - 10:19 PM

Get MODX Context Settings and optionally output to placeholders.

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);