I have spent HOURS trying to solve a rather trivial problem. Eventually I came up with a solution so simple that I wish I had thought of it at 10am this morning >:(!
I will post it here in case it is useful to anyone else.
The problem:
In the sidebar of any news item page, I want to have a list linking to other news items. Obviously I do not want to show the item that is currently being viewed in that list, so I need to set up a filter to exclude it.
How NOT to do it:
By trying to find a ’clever’ filter condition using PHP’s ’variable variables’. They seem a bit flaky in anything but the simplest form.
How to do it in under 5 minutes:
In the NewsListing snippet, replace
$filterName= $filterArray[1];
with
$filterName= ($filterArray[1]=='[+self+]') ? $modx->documentObject['id'] : $filterArray[1];
and in your call to the snippet set a filter, so:
I really did not want to modify the snippet if possible, but it does the trick and I can now get on with some ’proper’ work. However, if anyone can think of a more elegant solution please let me know.