Looking for suggestions to quickly solve an annoying Bad Link Tag, that continues to plague my error console for myriad resources. I’ve finally isolated to the fact that I have a button that appears for connecting to a photo gallery. However…once a resource is pulled into an archive folder… I unpublish the gallery — yet… this gallery button is trying to still load a url for a gallery that no longer is publish… thus the bad link. This is my mistake for the way I original built this part of the website. I am wondering though — as a quick work-around… is it recommended that I just find the button in the database, and turn it off. Otherwise, I have to look at the log, and then go and open each resource, toggle through TVs to find that button and uncheck it. First I’d like to get the button in question turned off, and then go back and rework the template, and how that button appears — as in perhaps create a conditional that allows the gallery button to display with link only when the gallery is published.
I’m not officially recommending this, but as a temporary solution, you can stop the error messages by making a very small change in the code of the MODX parser.
In MODX 2, it’s core/model/modx/modparser.class.php
around line 1366.
In MODX 3 its core/src/Revolution/modLinkTag.php
around line 107.
Find a line that starts out like this:
if (empty($this->_output)) {
$this->modx->log(
modX::LOG_LEVEL_ERROR,
'Bad link tag`
Be sure it contains ‘Bad link tag’.
If you make this change in the first line by adding false &&
before the word empty
the error messages will stop (there needs to be a space between &&
and empty
). It’s easy to undo by just removing false &&
.
if (false && empty($this->_output)) {
$this->modx->log(
modX::LOG_LEVEL_ERROR,
'Bad link tag
Thank you for responding with this solution Bob. I downloaded the error log and went through resource by resource, and unchecked the template variable for the button and solved the issue. Basically I have in my template chunk… a variable for inserting a link to a photo gallery resource. And then, I have a template variable for displaying a button that users can click to load the photo gallery. In the case where I have turned off and remove the link the gallery, but the button still resides on the page… I get the error. I have to review that button variable and/or create a conditional that states, if the gallery field has a link to a resource then display a button… I do appreciate the feedback, and good to hear from you. Hope all is well.
Can you clarify what this means? How, exactly, is it “turned off” ?
And what is different about the pages where it’s turned off vs on?
Is there a TV for the page that could be checked to see whether the button should be displayed?
Checked vs Unchecked. When I have a gallery for the real estate property… I select the gallery from a TV select menu. Then I check my TV checkbox… than in turn… loads the link to the resource. There was some logic for my building it this way “at the time it was built”, but clearly I should have used a little more logic. Ha!
I’m nearing a solution. I put a variable in the chunk for the button. So when the button is displayed, but no gallery link is inserted… the result is the bad link. <a class="button small" href="[[~[[*link2gallery]]]]">PHOTOS</a>
I should, if possible, make it so IF a gallery is selected… a button appears on the page. My gallery TV input type is a “resource list”. So IF a gallery is published… it appears in the list. Certainly not the best approach, but it’s what I could muster up at the time I was learning and building.
You might consider a custom snippet that returned the HTML code for the button if the gallery TV is not empty. This code would be very fast and should avoid cache problems.
Something like this (untested):
Put this where the button goes:
[[!ButtonSnippet]]
Create a snippet called ButtonSnippet with this code:
/* ButtonSnippet code */
/* See if the TV value is empty */
$tvId = 'Gallery'; // (name of TV);
$tvr = $modx->getObject('modTemplateVarResource', array(
'tmplvarid' => $tvId,
'contentid' => $modx->resource->get('id'),
));
$buttonCode = 'HTML For Button here';
/* Show button if TV value is empty */
if (! empty($tvr->get('value'))) {
$output = $buttonCode;
} else {
$output = ""; // or some empty HTML
}
return $output;
Thank you for offering this Bob. I will give it a try this evening and get back to ya.