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
$modResource->getTVValue(‘photo’)
Here is what I get:
assets/images/photos/banana-cake.jpg
So when you read the value directly from the database with code like this, the value is correct?
<?php
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.
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.