Is it possible to read the date set by a TV in order to determine which template to use for each resource?
I'm thinking of a list of events, whereby one template could be used for current events and another for past ones - i.e. if the end date (TV) is after today, assign a "current" template.
-
☆ A M B ☆
- 24,524 Posts
It is a little awkward to assign templates at run-time, since such resources can't be cached. It's better to use CSS, and then you can use a snippet or an output modifier to check the date and return the name of the desired .css file to use.
I'm not sure I fully understand - but maybe that's due to not phrasing my question clearly enough.
I was't necessarily planning on doing much more than altering the CSS class of the containing element. However, I assumed that assigning a different tpl chunk within getResources would be the obvious way to achieve this. I suppose what I'm less clear on is how feasible it is to measure the date value of a TV via getResources against the current date.
-
☆ A M B ☆
- 24,524 Posts
Ah. Not the entire page template, just the getResources tpl.
According to the docs, tplCondition only works with resource fields, not TVs. So I don't know of any way you could do it by TV.
Well, you could use an output modifier to insert some inline CSS in the tpl.
-
☆ A M B ☆
- 24,524 Posts
Well, after looking at the docs for output modifiers, you'd probably do better with a snippet in the tpl to output the inline CSS. It could be done with an output modifier, but it would be pretty complicated.
Actually, a custom output modifier (which is just a snippet anyway) would make it easier to deal with the TV value, instead of having to get the TV value in the snippet code.
-
☆ A M B ☆
- 24,524 Posts
Here's a snippet I called "setCSS" to use as a custom output modifier for dates 1 week ago:
<?php
$cutoff = strtotime("-1 week");
$tvdate = strtotime($input);
if($tvdate < $cutoff) { return "blue"; } // or whatever you want
else { return "green"; } // or whatever you want
return;
And the output modifier:
[[+tvDate:setCSS]]
-
☆ A M B ☆
- 24,524 Posts
You could use that snippet to output a classname if you wanted, then your .css file would handle the styling. The tpl could look something like this:
<article class="block [[+tvDate:setCSS]]">
etc...
</article>
Wow, OK, a few things to try and get to grips with.
The "setCSS" snippet as output modifier looks like it could be just the thing.
I assume that the $input argument is what's passed in from the tvDate placeholder?
[ed. note: chr.s last edited this post 11 years, 1 month ago.]
-
☆ A M B ☆
- 24,524 Posts
All output modifiers have access to several values, including the value of the element it's being used on.
http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-%28output-modifiers%29#InputandOutputFilters%28OutputModifiers%29-CreatingaCustomOutputModifier
I don't think the TV filters will do what you want, it is used for determining which resources to show.