esger
October 18, 2022, 3:42pm
1
Using [[~[[+tv.pageLink]]]]
throws lots of errors in the error log. (bad link tag)
The tv.pageLink
is not set most of the times, which causes the errors.
So I try
[[+tv.pageLink:notempty=`[[~[[tv.pageLink]]]]`]]
but that doesn’t help since the inner part is being parsed nonetheless.
Isn’t there a ‘standard’ way available in ModX to do this without it clogging the error-log?
Maybe this works:
[[ [[+tv.pageLink:notempty=`~[[+tv.pageLink]]`]] ]]
But as this is a bit ridiculous, it’s probably a better idea to create a custom snippet that uses $modx->makeUrl() when the TV is not empty.
1 Like
jako
October 18, 2022, 10:52pm
3
This output filter can help:
<?php
/**
* LinkThis
* Generate a link from an integer, that references a resource or a weblink (and its content value). Otherwise, use the value as an url. If the link is empty try the same with an optional default value.
*
* @author Thomas Jakobi <office@treehillstudio.com>
*
* @usage [[+placeholder:linkthis=`default`]]
*/
/** @var modX $modx */
/** @var array $scriptProperties */
$value = $modx->getOption('input', $scriptProperties, '');
$default = $modx->getOption('options', $scriptProperties, '');
if (!function_exists('linkthis')) {
function linkthis($modx, $value)
{
if (filter_var($value, FILTER_VALIDATE_INT) !== false) {
$resource = $modx->getObject('modResource', $value);
if ($resource) {
if ($resource->get('content_type') === 'modWebLink' || $resource->get('content_type') === 'MODX\Revolution\modWebLink') {
return ($resource->get('content')) ? $modx->makeUrl($resource->get('content')) : '';
} else {
return $modx->makeUrl($value);
}
} elseif ($value) {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'The resource ' . $value . ' does not exist!');
return $value;
} else {
return '';
}
} elseif ($value) {
return $value;
} else {
return '';
}
}
}
$result = linkthis($modx, $value);
if (!$result) {
$result = linkthis($modx, $default);
}
return $result;
1 Like
esger
October 19, 2022, 7:20am
4
I’m not sure why it is ridiculous. What would be a valid use case for [[ ~[[+tv.pageLink]] ]]
or [[ ~[[+id]] ]]
then?
esger
October 19, 2022, 7:21am
5
I’ll keep this in mind as the bad link tag error will come back at me
system
Closed
October 21, 2022, 7:22am
6
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”.