Simple question! I have a chunk which needs to display [[++site_url]] of a specific context (say 'web') no matter where it is placed, including in other contexts with different [[++site_url]]s.
How do I do this?
Thanks!
-
☆ A M B ☆
- 3,141 Posts
First thing that comes to mind is a snippet along these lines..
<?php
$context = $modx->getObject('modContext', $ctx);
if ($context) {
return $context->getOption('site_url');
}
return 'ctx not found';
used as
[[getSiteUrl? &ctx=`web`]]
I think this would do it:
[[getContextSetting? &context=`someContext`, $setting=`site_start`]]
<?php
/* getContextSetting snippet */
$ctx = $modx->getOption('context', $scriptProperties, null);
$setting = $modx->getOption('setting', $scriptProperties, null);
if ($ctx == null) {
return 'No Context set';
} elseif ($setting === null) {
return 'No Setting set';
} else {
$csObj = $modx->getObject('modContextSetting',
array('context_key' => $ctx,
'key' => $setting
)
);
}
if ($csObj) {
return $csObj->get('value');
} else {
return 'Context Setting not found';
}
Thanks Bob - works great!