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
[[~174? &scheme=`full` &context=`tools`]]`

doesn’t work for cross context in my case, but FastField eand pdoField work (MODX Revolution 2.8.4-pl).

Then the context is wrong. Please look in the MODX error log. The reason should be logged.

[2024-12-24 11:01:05] (ERROR in resource 890 @ /var/www/XXXXXX/XXXX/XXXXX/XXXXX/XXXXXX/model/modx/modparser.class.php : 1373) Bad link tag `[[~191? &scheme=`full` &context=`tools`]]` 

encountered

If

[[~191? &scheme=`full` &context=`tools`]]

is in a “tools” context resource, it works

What happens if you leave out the &context property?

If the context is set up correctly, it should use the current context by default.