Hi All.
I'm trying to track down some errors I'm getting from a snippet that gets the height and width of an image using getimagesize();. I run the snipped inside an IF statement that checks there's actually an image in the TV field;
[[!If? &subject=`[[+icon]]` &operator=`notempty` &then=`[[!mySnippet]]" &else=``]]
But for every field that does not have an image I get the error; "... warning: getimagesize(): Filename cannot be empty" These errors pile up and slow down page loads.
The error seems weird because the snippet should not execute, but it is.
[[+icon]] is part of a MIGX TV so using a Chunk after then= isn't an option.
Is it possible to check for an empty field in an if / else statement in the snippet? Any suggestions would be welcome.
Thanks!
My config is: MODX Revolution 2.3
MODX runs your snippet when it parses the tag.
This might work:
[[[[!If? &subject=`[[+icon]]` &operator=`notempty` &then=`!mySnippet" &else=``]]]]
But why not just see if the icon is empty in your own snippet and return '' if it is? That would be more efficient.
[[!MySnippet? &icon=`[[+icon]]`]]
$icon = $modx->getOption('icon', $scriptProperties, '');
if (empty($icon)) {
return '';
}
/* The rest of your snippet here */
Hey BobRay!
Of course the second option worked. As always, thanks.
I use my original snippet in a lot of places so I was trying to write the IF statement globally so that any empty field would not run the script. But I don't think that's possible, right?
Again, thanks,
Rob
Did you try the first option? It shouldn't run the script unless the icon tag is not empty.
I did try the first option and still saw the errors, weird.
The second option will be faster anyway.