Cross Context links

I created a context, and I have a subdomain pointing to it. vote.mysite.com

I’m using PDOpage and PDOmenu to pull content from the main context WEB. The [[~[[+id]]]] in the VOTE context are making links to the subdomain. How can I get it to make links to the WEB context?

I don’t think you can do it with a link tag, but a custom snippet (call it MyWebLink) should work.

Tag:

<a href="[[!MyWebLink? &id=`[[+id]]` &context=`web`]]">Link Text</a>

Snippet:

/* MyWebLink Snippet */

$id = $modx->getOption('id', $scriptProperties);
$context = $modx->getOption('context', $scriptProperties);

return $modx->makeUrl($id, $context, "", "full);

You may have to play with the caching in the tag to get it to work. The example above is my best guess on the correct version.

You probably have to create a context setting site_url (and maybe http_host as well) in the “web” context.

I think otherwise, the value $_SERVER['HTTP_HOST'] of the current request is used to create the URLs (which has the wrong value for links to the main context).

You can do this also with a link tag: [[~[[+id]]? &scheme=`full` &context=`web`]] Normally you don’t need to use &context=`web`, since MODX detects this on its own.

2 Likes