pdoResources createdon within-last-week filter

In a pdoResources template is there a way to show some HTML if +createdon was within the last week? The following strotime section doesn’t seem to work inside pdoResources, but I’m not sure what the syntax needs to be. I tried replacing strtotime with another reference to “date” again, but that didn’t work.

[[+createdon:date:>=[[strtotime("-1 week")]]?then=`<span class="label">New!</span>`:else=``]]

Here is a possible solution using MODX output modifiers

[[!+createdon:gte=`[[!+oneweekago:default=`-1 week`:strtotime]]`:then=`<span class="label">New!</span>`]]

or you could also use Fenom

{set $oneweekago = '-1 week' | strtotime}
{if $createdon >= $oneweekago }<span class="label">New!</span>{/if}
1 Like

If using Fenom like that, where you are setting a variable, would it work if set in the outer wrapper, which then gets used over and over by the inner wrapper? Or would it not matter or be better to keep it with the item using the variable?

Wrapper tpl:

{set $oneweekago = '-1 week' | strtotime}
<ul>
  [[+output]]
</ul>

List tpl:

<li>[[+pagetitle]] {if $createdon >= $oneweekago }<span class="label">New!</span>{/if}</li>

I don’t think it would work.
My guess is that this variable is only available in the current chunk that gets processed.
Also, the ‘wrapper chunk’ is only processed after all ‘item chunks’ have been parsed.

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.