getTVValue add a backslash in a path


OS : MacOs Sonoma 14.3.1
Modx : 3.0.
TV name : photo
TV input type : image
TV output Type : default
MAMP Pro : 6.9

I’m using getTVValue to get the path of a photo. Example :
The path for a photo is: "assets/images/photos/banana-cake.jpg
Here is what I get:

How do you get rid of backslashes?

Thanks for your help.

So where are these backslashes that get added?
What am I missing?

Can you give us an example of how you’d like it to look?

Sorry, I should have used the preformatted text, here is what I get:


Is the value already stored like this (with the backslashes) in the database?
(Database table modx_site_tmplvar_contentvalues column value)

No, the value is stored with no backslashes like this :



Could there be a php.ini file loaded by MAMP Pro, or something in your .htaccess that is causing forward slashes to be escaped?

Something like addslashes. (Although I understand this particular feature does not escape forward slashes).

It may be helpful to provide your php version number to the spec in your post.

So when you read the value directly from the database with code like this, the value is correct?

use MODX\Revolution\modTemplateVarResource;

$tvID = 17; // <-- change this to the ID of the TV 'photo'
$tplVarResource = $modx->getObject(modTemplateVarResource::class, ['tmplvarid' => $tvID, 'contentid' => $modx->resource->get('id')]);
$tvValue = '';
if ($tplVarResource) {
    $tvValue = $tplVarResource->get('value');
return $tvValue;

The function getTVValue() does some additional stuff (like prepending the path if a media source is used and rendering the output if a TV Output Type is used), but I don’t see where or how those backslashes could be added.

I carried out tests with the following versions of PHP available on MAMP PRO:


and I got the same result.


Do you have any custom Plugins (under Elements) that could be causing this behaviour?


First of all thanks, when I use only your code I get the path without backslah. This allowed me to identify where my problem really came from.

The path that I obtained with getTVVAlue was added as an element to an array, to then transform this array into JSON format with the following function:

json_encode($myArr, JSON_PRETTY_PRINT);

when I should have used

json_encode($myArr, JSON_UNESCAPED_SLASHES);

Thank you all for your generous help and have a nice day.