Media Source path troubles

I’ve setup a media source which points to the directory images/ and also set the default_media_source setting to this media source. When I now edit the profile image of an user, I only see the folders and files within the images/ directory, like intended.

Now, when I browse the images and select one, I see the full path in the bottom of the media selection window (e.g. /images/team/name.jpg). After hitting OK, the path shown is only team/name.jpg which results in my frontend not showing the image because the file path is only team/name.jpg (instead of /images/team/name.jpg).

How can I tell MODX to use the full path? I feel like I missed something here, so I appreciate any help!

If this is relevant: I use the Peoples Extra to get the user image via the [[+photo]] placeholder.

It is allways only stored the path without the mediasource-path.
If you want the full-path in the frontend, you could create a output-filter-snippet, like that

$output = str_replace('./','',$input);
if ($mediasource = $modx->getObject('sources.modMediaSource',$options)){
    $output = $mediasource->prepareOutputUrl($output);
}
return '/' . $output;

and use it on your placeholder like:

[[+photo:addmediasourcepath=`3`]]

in this case 3 is the mediasource - id

1 Like

Shouldn’t the base path of the used media source always be added to any media? In my understanding this current behaviour makes it very unmodular. If someone could explain why I’m wrong here, I would probably learn a lot :wink:

If I have to edit this manually, I guess I’ll rather simply put the base path images/ manually before the placeholder as I know this won’t change in the future and is easier to do, but I really appreciate your option @bruno17, I’m sure this will help me in other occasions in the future, so thank you!

Does setting the media source to use a relative base path help?

On how it got this way:

IIRC, media sources used to prepend the base path automatically, but that made it impossible to create file media sources outside the MODX root and prevented files in a moved core directory above the web root from showing in the Files tree (Show Moved MODX Core in File Tree).

1 Like

No, unfortunately not. Base path and URL were already set to be relative.

But thanks for the explanation, that does make sense.

Okay, now I’m really confused: I also have an image TV for my header images in Articles. I also changed that TV to use the images/ media source in the manager. But now my images are not showing on the front-end because the URL ends up showing double images/ like images/images/blog/image.jpg (correct would be images/blog/image.jpg). To be clear, I didn’t even put anything before the placeholder.

So it looks like the default media source IS added to the TV path here and the TV uses the full path as well (unlike the user image field which ignores the base media source path). Why is that?

Edit: the whole double images/ couldn’t be reproduced now, so that might have been just a cache issue or something…

this has todo with the way, how tags are processed.
MODX adds the mediasource - path automatically to the stored path, when you use TV-tags

I think, also getResources processed TV-values in a way, which adds the mediasource - path automatically, while peoples does this not with the user-field

1 Like

Okay, that makes sense. So the issue is not the media source itself, but the way resources are called by different Extras or Snippets?

Right. Peoples gets the image from the ‘photo’ field of the User Profile and probably doesn’t know anything about Media Sources since it was written before they existed. Even if it did, I don’t think it would have any way of knowing which Media Source to use.

You can probably add whatever you need to (i.e., images/. or [[++site_url]]images/) in front of the photo placeholder in the Peoples Tpl chunk.

2 Likes

That’s exactly what I did, I just felt this wasn’t as MODX modular as usual to hardcode a path. But I don’t think the image path will change anytime soon anyway, so that’s totally fine.

Thanks!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.