peace_love
peace_love

Reputation: 6471

How can I group my entries by TV with getResources (ModX)?

I have a getResources call, the result looks more or less like this:

I can sort them by tags:

It works very well. This is my code:

[[!getResourcesTag?
             &parents=2`  
             &tagKey=`Tags` 
             &showHidden=`1`
             &tpl=`datesTpl
             &limit=`3`
             &includeContent=`1`
             &includeTVs=`1`
             &processTVs=`1`
             &tvPrefix=`` 
             &hideContainers=`1`
             &pageLimit=`10` 
         ]]

Now comes the part, that makes problems to me. I want to group the result by month. So the result I would like to achieve is:

January 2016

01.01.2016 - new year's lunch (meetings)

December 2015

November 2015

The TV, that outputs the date has the name "date". This TV gives me for every entry a timestamp output. For example: "2015-12-11 00:56:00". I wrote a snippet (formatDate), that outputs me later the format I wish. I use it like this:

[[formatDate? &date=`[[+date]]`]]

So I thought I could use Archivist Grouper for that issue. But it is not working. Somehow it doesn't process my TVs. Here is my code: 1

[[!ArchivistGrouper? &parents=`2` &itemTpl=`datesTpl` &includeTVs=`1` &tvPrefix=`` &includeContent=`1` &processTVs=`1`]]

My result with Archivist Grouper is:

January 2016

December 2015

November 2015

So my question is, can I get the result I wish also with getResources? Or do you have any idea to get it run! I hope very much you can help. I am happy for every hint smiley

Upvotes: 2

Views: 459

Answers (2)

Karchunk
Karchunk

Reputation: 1

This will break it up by year.

[[pdoNeighbors?
    &id=`[[+id]]`
    &tplWrapper=`@INLINE [[+next]]`
    &sortby=`publishedon`
    &sortdir=`asc`
    &tplNext=`@INLINE [[+publishedon:strtotime:date=`%Y`]]`
    &toPlaceholder=`neighborYear`
]]
[[+neighborYear:notequalto=`[[+year]]`:then=`<h3>[[+neighborYear]]</h3>`]]
   <dt>[[+publishedon:strtotime:date=`%m/%d/%Y`]]</dt>
   <dd><a href="[[~[[+id]]]]" [[+link_attributes]] title="[[+pagetitle]]">[[+pagetitle]]</a></dd>
[[+publishedon:strtotime:date=`%Y`:toPlaceholder=`year`]]

To break it down further by year and month use %Y%m

Upvotes: 0

Sean Kimball
Sean Kimball

Reputation: 4494

you will not be able to set up getResources to output anything in a grouped format. You will have to write your own snippet.

You can turn on debugging in getResources to see what sort of query it is outputting and either copy that to your snippet [not so great] or rebuild it using xPDO [better], iterate through that to get your grouping and you would have to bone up on getChunk to format your output.

Upvotes: 0

Related Questions