-
- 20 Posts
I’m using getResources to display news, pooled from a number of different resource parents. It works great.
I’m trying to make it so that each article has a different thumbnail based on which section it is in, or to use ModX parlance: what the UltimateParent of it is.
If I put this in my getResources template, I get the result you’d expect:
[[UltimateParent? &id=`[[+id]]`]]
It returns the ID of the section the news article is in.
But if I use UltimateParent within an output modifier the I get nothing. I’m trying to use this:
[[[[UltimateParent? &id=`[[+id]]`]]:is=`5`:then=`MOTORSPORT.JPG`:else=`DEFAULT.jpg`]]
I hope you can understand what I’m getting at. Any other methods to return news and a different thumbnail depending on UltimateParent in which the resource lives would be greatly appreciated. In the old days of Evo, I often did this with PHx, but am I right in thinking that output modifiers have largely replaced this need?
I’m on 2.1.2-pl with the latest getResources (1.3.1).
Try updateing to 2.1.3 - a placeholder parsing issue was introduced in 2.1.2 and while I don’t know the technical details of that, I think you may be running into that.
If that doesn’t work we’ll have to try something else.
-
- 20 Posts
Oh, good call. I’ve upgraded, cleared cache, and everything seems the same unfortunately.
Try this:
[[UltimateParent:is=`5`:then=`MOTORSPORT.JPG`:else=`DEFAULT.jpg`? &id=`[[+id]]`]]
-
- 20 Posts
That appears to be working perfectly. Thank you very much.
This is a trick I’ll be using again and again I think. Do you think there should be any performance problems with this, as I heard there are real issues achieving a simliar thing using the ’if’ snippet?
The main problem with the If snippet is people using it uncached, and 40 times in a template.
It can be better to use If compared to output modifiers in certain cases, as output filters output is not necessarily cached IIRC while snippet output (when not called uncached...) definitely is.
There’s also a snippet called Switch that allows you to sort of chain a bunch of If snippets which should have a great impact if you’re using a number of If snippet calls or Output filters checking on one value.
-
- 20 Posts
Ah, I doubt that will be an issue then.
I’m taking this a step further, so it only uses a default thumbnail (one of 3 depending on the section it is in) if one has not been supplied. The code is:
<img src="[[+tv.newsImage:is=``:then=`[[UltimateParent:is=`5`:then=`default-news-motorsport.jpg`:is=`6`:then=`default-news-football.jpg`:else=`news.jpg`? &id=`[[+id]]`]]`:else=`[[+tv.newsImage]]`]]" alt="[[+pagetitle]]" />
It throws out some nasty errors, parse errors.
Am I being too ambitious here with what can be achieved? I have something to fall back on, but it’d be nice if I could do it this way.
You can do it that way.
Another, more clean solution perhaps, could be using that TV you’re using and setting it’s default input value as @INHERIT - that will inherit the value of the resource one level up in the hierarchy then by default. And you can set a different one per resource. @INHERIT is what’s called a binding:
http://rtfm.modx.com/display/revolution20/Bindings