Media source - cultureKey

Hello all,

I am currently trying to create a media source for multiple contexts. Each context has its own cultureKey (de,en,es,ru…).

For each context a folder has been created (assets/de/, assets/en/, assets/es/, assets/ru/).

In the frontend I always get the correct path, because the cultureKey is interpreted correctly. In the backend when uploading the system always accesses the “de” folder.

Here are the media source settings:
basePath: assets/[[++cultureKey]]/
baseUrl: assets/[[++cultureKey]]/

What am I doing wrong?

Hi @joe-petts,

If you’re in the manager then the active cultureKey will be the one in the system settings.
So I don’t think it’s going to work the way you expect unfortunately.

Can you give a bit more information about what you’re trying to achieve with the media source?

1 Like

Hi @digitalpenguin,
I was afraid that the backend only knows the one key.

I want to create multiple media sources for different areas (slider, gallery, content…). I used Babel for multilingual and so I have 9 contexts for the different languages.

I want to have a different file in the right folder (CultureKey) for each language.

de/slider, en/slider, fr/slider, ru/slider…
de/gallery, en/gallery, fr/gallery, ru/gallery…
de/content, en/content, fr/content, ru/content…

For example, if I want to have one media source for a slider, I would now have to create a single slider media source for each language.

That’s why my idea was to work with the CultureKey, then I would only need one media source for each area.

Does really nobody have an idea that could help me?

I think you’ll need to create media sources in the regular way.

You would create them with the language codes in the manager so you can still access them via cultureKey on the other contexts.

For example:

English: assets/en/
French: assets/fr/


On the language contexts you would then do something like [[++assets_url]][[++cultureKey]]

1 Like

Was hoping someone had used a different way to avoid the myriad of media sources.

Thanks for the support anyway!

if you are using this mediasources only from the resource-edit panel, you could try to use a snippet instead of the systemsetting placeholder to determine the correct coultureKey. Maybe have a look into this snippet:

1 Like

Are you producing and uploading different files for each language? As in the actual photo file for the de slider would be different than the photo file for other language slider? If so, would it be possible to name the files an identical name but with a suffix of the language key; de or ru, etc. And then in the img path use the culture key setting to do the switching? That would allow you to upload them all to just one slider folder I think…

1 Like

Yes, each TV should get its own folder in the folder of the language. Unfortunately, with the suffix the images still end up in one folder. But thanks for the approach!

I have taken information from the MIGX snippet and written the following snippet “backendKey”:

$id = 2;
$resource = $modx->getObject('modResource', $id);
$ctx = $resource->get('context_key');
return $ctx;

When I enter the snippet in Media Source like this, it works and gives me the folder with the CultureKey (en) of Resource 2.

basePath: assets/[[backendKey]]/slider/

Then I tried to use a placeholder, unfortunately this resulted in an error:

//$id = 2;
$resource = $modx->getObject('modResource', $id);
$ctx = $resource->get('context_key');
return $ctx;

basePath: assets/[[!backendKey? &id=[[+id]]]]/slider/

Does the placeholder have to be used differently in that case?

the mediasource doesn’t have a placeholder set with [[+id]]

to get the resource-id, while you are in the manager you will need to read the $_SERVER[‘HTTP_REFERER’]

like done here

1 Like

but you could just use that snippet, as it is and use the {context_key} - placeholder in the pathTpl

1 Like

I already tried the solution with the original MIGX snippet and it worked. Thanks for that!

basePath: [[migxResourceMediaPath? &pathTpl=assets/{context_key}/slider/]]

After your hint I have now rewritten the snippet as follows and it works!

Snippet: backendKey


$parsedUrl = parse_url($_SERVER['HTTP_REFERER']);
parse_str($parsedUrl['query'], $parsedQuery);

if (isset($parsedQuery['amp;id'])) {
    $docid = (int)$parsedQuery['amp;id'];
    $resource = $modx->getObject('modResource', $docid );
    $ctx = $resource->get('context_key');
    $modx->log(MODX_LOG_LEVEL_ERROR, "[migxResourceMediaPath]: docid: $ctx");
    return $ctx;

basePath in Mediasource: assets/[[backendKey]]/slider/

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.