Display conditional archive

I have created a “Programm(3)” container resource made with “Article” Extra.
I need to categorize those by “Exhibition” and “Others”.
But the “article container” doesn’t support the child/dropdown menu that’s why I made “Programs(32)” resources where I fetched the resources by Pdoresources and filtered them by a future date timeframe.

Template: Program

[[pdoResources?
  &parents=`3`
  &includeTVs=`article_type, date_from, expire_date, post_feature_image, artist, assign_artist`
  &processTVs=`1`
  &where=`{
      "date_from: <= ": "[[!getDate:date=`%Y-%m-%d 00:00:00`]]",
      "expire_date: >= ": "[[!getDate:date=`%Y-%m-%d 00:00:00`]]"
  }`
  &tpl=`program_item`
]]

Template: Exhibition

[[pdoResources?
  &parents=`3`
  &sortby=`{"pagetitle":"ASC"}`
  &includeTVs=`article_type, date_from, expire_date, articlestags, post_feature_image, assign_artist`
  &where=`{
      "article_type: = ": "Exhibition",
      "expire_date: < ": "[[!getDate:date=`%Y-%m-%d 00:00:00`]]"
  }`
  &tpl=`program_item`
]]

Now in the Exhibition page, I need the Archive year list(2020, 2021, 2022, 2023) and search form those will need to filter by the exhibition.

Note: Exhibition and Others are tv field
Site URL: http://modx.stiftungstarke.de/

What exactly is the question here?

Do you want to adjust the snippets from the Archivist extra, so that they filter the data by a TV value?

Or do you want to create some custom code (maybe using pdoResources) that filters the resources by date (like in this older thread of yours)?


What do mean by “search form”? Should the data additionally also be filtered by a search term? What fields should be searched?

Maybe this thread is helpful:

Exhibitions are past programs.
On the Exhibitions page, I want to display the years(2020, 2021, 2022).
When I will click on the year, under the year past programs will display
and also will be filtered by tv field “Exhibitions”

As the Articles extra depends on the extra Archivist, you can probably use the snippets of this extra to achieve what you want.

For example the snippet “Archivist” outputs a list of available dates. You can use the &where property with an EXISTS subquery to filter by the value of a TV:

[[!Archivist?
    &parents=`3`
    &target=`33`
    &limit=`0`
    &where=`["EXISTS (SELECT 1 FROM modx_site_tmplvars t INNER JOIN modx_site_tmplvar_contentvalues tc ON tc.tmplvarid = t.id WHERE t.name = 'article_type' AND tc.contentid = modResource.id AND tc.value = 'Exhibition')"]`
]]

it redirects to “stiftungstarke.de/exhibitions2023/06

ArchivistTpl code below:

<li class="[[+cls]]">
    <a href="[[+url]]" title="[[+date]]">[[+year]]</a>
</li>

Try setting the “Container” field (isfolder) of the “Exhibitions” resource to true.


If this doesn’t work, then duplicate the “Archivist” snippet, and change the code in the marked line, so that there is a / between the resource alias and the year.

Sorry, I can’t find this.
Note: Instead of “Exhibitions”, I want to display the years on the Archive page. and the Archive page is not a container. Fetching the programs from another container(id:3)

Visit this link.
Here are displaying years multiple times as months and url is not working also.
If I put the “/”, even then it doens’t work “modx.stiftungstarke.de/archiv/2023/06

Archive page:
[[!Archivist? &parents=`3` &target=`50` &tpl=`ArchivistTpl`]]

ArchivistTpl:

<li class="[[+cls]]">
    <a href="[[+url]]">[[+year]]</a>
</li>```

You can change every resource to be a container. In the resource, go to the tab “Settings” and change the checkbox “Container” to true.

modx_container_setting


In the call to the Archivist snippet set the property useMonth to 0.


On your Archive page, in the call to getArchives, try setting the property &showHidden to 1 (as the extra Articles sets the hidden flag for all the articles).

[[!getArchives?
   &parents=`3`
   &showHidden=`1`
   ...
]]

Page url: Archiv - MODX Revolution
on click the year link showing no changes, no filter

<ul class="news-archive gap-6">
  [[!Archivist? &parents=`3` &target=`50` &tpl=`ArchivistTpl` &useMonth=`0`]]
  [[!getArchives?
     &parents=`3`
     &showHidden=`1`
     &tpl=`@CODE:<h2 class="title"><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>`
  ]]
  [[!+archives]]
</ul>

@CODE: doesn’t seem to work here. Use @INLINE or a proper chunk instead.

&tpl=`@INLINE <h2 class="title"><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>`

Sorry for asking repeatedly, It work’s with the proper chunk.
But how can I filter them by custom tv, I have a time frame, and after the time frame excess program will display here on the archive page.

And here I have couple of custom tv those are not showing

[[!getArchives?
  &parents=`3`
  &showHidden=`1`
  &tpl=`archiveTpl`
  &where=`{
      "expire_date: < ": "[[!getDate:date=`%Y-%m-%d 00:00:00`]]"
  }`
]]

How can I display the custom tv and filter the items with custom tv?

getArchives internally calls the snippet getResources. So you should be able to use all the properties from the getResources snippet.

It should also be possible to use pdoResources instead by setting the property &grSnippet.

Not understanding &grSnippet
and how to setting it up?

[[!getArchives?
    &grSnippet=`pdoResources`
    ...
]]

I really owe to you. Everything is working fine except active class on the link(2022, 2023)

ArchivistTpl

<li class="[[!+active:class=`active`]]">
    <a class="[[+active]]" href="[[+url]]">[[+year]]</a>
</li>

Is the “SimpleSearch” correct?
If not, how to make this correct?
and see I also have an archive on this page, because of the archive, by default displays the latest year’s(2023) archive posts.
But I also would like to search form here. how to manage these two together, search results + archive results?

<ul class="news-archive gap-6">
    [[!Archivist? &parents=`3` &target=`50` &tpl=`ArchivistTpl` &useMonth=`0`]]
</ul>
  
<div class="relative">
    [[SimpleSearchForm? &tpl=`SearchForm`]]
    <h3>Result</h3>
    [[!SimpleSearch?
        &grSnippet=`pdoResources`
        &parents=`3`
        &showHidden=`1`
        &tpl=`program_item`
        &sortby=`{"pagetitle":"ASC"}`
        &includeTVs=`article_type, date_from, expire_date, post_feature_image, assign_artist`
        &where=`{
            "expire_date: < ": "[[!getDate:date=`%Y-%m-%d 00:00:00`]]"
        }`
    ]]
</div>
  
<div class="news-list">
    [[!getArchives?
        &grSnippet=`pdoResources`
        &parents=`3`
        &showHidden=`1`
        &tpl=`program_item`
        &sortby=`{"pagetitle":"ASC"}`
        &includeTVs=`article_type, date_from, expire_date, post_feature_image, assign_artist`
        &where=`{
            "expire_date: < ": "[[!getDate:date=`%Y-%m-%d 00:00:00`]]"
        }`
    ]]
</div>

This is not how it works. You can’t just randomly combine snippets and properties and hope that it works. The property &grSnippet is specific to getArchives. SimpleSearch doesn’t use getResources/pdoResources. You can only use the properties SimpleSearch itself provides.


In general, if you want to achieve something specific like in this case, you’ll most likely have to start writing some custom code.

If you want to show the search results if there was a search and the exhibitions from a certain year otherwise, then for example write a snippet that checks the request parameters:

  • If there is a request parameter “search”, then it is a search → run SimpleSearch
  • If there is a request parameter “arc_year” → run getArchives to display the exhibitions from that year.

If you want to combine the search with the filtering, take a look a this topic for a possible solution:

The snippet Archivist doesn’t provide a placeholder [[+active]]. You either have to duplicate the snippet and adjust it to your needs, or maybe write a custom snippet like this:

Template chunk:

<li class="[[!IsActiveYear? &year=`[[+year]]`]]">

Snippet “IsActiveYear”:

<?php
$year_param = (int) $_GET['arc_year'] ?? 0; // Read the value of the request parameter 'arc_year'
if ($year_param == $year){ // Compare it to the value of the 'year' property from the snippet call
    return 'active';
}
return '';

When you call the URL .../archiv/2023, it gets converted to .../archiv/?arc_year=2023. You can check the request parameter arc_year to test if the value is equal to the year in this list item.