//$tv_image is the TV that contains the Image Widget. // has $tv_image been defined? If not, default to contentImage. if( !$tv_image ) { $tv_image = "contentImage"; } // fetch the src for the image to be used in the content. $tv = $modx->getTemplateVar($tv_image); $src = $tv['value']; // if there is an image selected, find and return the output of the TV. if ($src) { // fetch the document's current id. $currentid = $modx->documentObject['id']; // fetch the TV output and store it in $output. $value = $modx->getTemplateVarOutput($tv_image, $currentid); $output = $value[$tv_image]; // return return $output; }
// ********************************************* // SNIPPET: TV // Version: 1.0 // By: Kunal Kapoor // Slight mods by: Brett at The Man Can! // ********************************************* // // USAGE: // The image widget and the HTML Generic Tag // widgets return output even if the TV value // is empty. Use this snippet to call a TV // instead of calling the TV directly, in order // to avoid having empty DIVs and IMG tags. // // DETAILS: // http://modxcms.com/forums/index.php/topic,2940.0.html // // OPTIONS: // name The name of the TV that you're calling. // // EXAMPLE: // Call [!TV? &name=`colR` !] // instead of [*colR*] // // ********************************************* // Do not modify below. // $name is the TV that contains the Widget. // Has $name been defined? If not, return nothing. if( !$name ) { return ''; } // fetch the src for the TV to be used in the content. $tv_source = $modx->getTemplateVar($name); $src = $tv_source['value']; // if there is an image selected, find and return the output of the TV. if ($src) { // fetch the document's current id. $currentid = $modx->documentObject['id']; // fetch the TV output and store it in $output. $value = $modx->getTemplateVarOutput($name, $currentid); $output = $value[$name]; // return return $output; }
(I hope that’s OK with you.)
...
Thanks again Kunal for the original.
Thanks for that snippet, Kunal. The HTML Generic Tag widget has the same problem, so I did a quick recode of your snippet so that it’d be apparent that it works for both widgets. (I just changed the variable names, I think, and added a little documentation. I hope that’s OK with you.)
// ********************************************* // SNIPPET: TV // Version: 1.0 // By: Kunal Kapoor // Slight mods by: Brett at The Man Can! // ********************************************* // // USAGE: // The image widget and the HTML Generic Tag // widgets return output even if the TV value // is empty. Use this snippet to call a TV // instead of calling the TV directly, in order // to avoid having empty DIVs and IMG tags. // // DETAILS: // http://modxcms.com/forums/index.php/topic,2940.0.html // // OPTIONS: // name The name of the TV that you're calling. // // EXAMPLE: // Call [!TV? &name=`colR` !] // instead of [*colR*] // // ********************************************* // Do not modify below. // $name is the TV that contains the Widget. // Has $name been defined? If not, return nothing. if( !$name ) { return ''; } // fetch the src for the TV to be used in the content. $tv_source = $modx->getTemplateVar($name); $src = $tv_source['value']; // if there is an image selected, find and return the output of the TV. if ($src) { // fetch the document's current id. $currentid = $modx->documentObject['id']; // fetch the TV output and store it in $output. $value = $modx->getTemplateVarOutput($name, $currentid); $output = $value[$name]; // return return $output; }
Hopefully that helps somebody.
Thanks again Kunal for the original.
-Brett