Conditional keywords gte_date


(James Porich) #1

Hi guys,

 

Background:

 

Following on from yesterdays question, currently working on an existing project where the infrastructure isn't ideal so I'm working around what I can.
Currently working on an "Events" page and an "Archived Events" page, the issue being that the organisation has unfortunately not set these up as "Single Calendar Event" items but rather News Items as well as Standard Page assets :(

The goal:

 

Currently trying to make Events automated by comparing a metadata date field with the current date. Idea being that if the event has a value less than todays date it isn't listed on the "Events" page. The opposite true of the "Archived Events" page (past events are shown on this page).

Currently users are sorting between these two by moving items to different folders (current events and past events). Each page having an asset list pointing to the respective folder. This isn't ideal and can occasionally lead to old items being shown if people forget about events that have finished.

 

To get around this, I  am intending to use conditional keywords on the asset list to determine if the date has passed or not, however I can't seem to get the date comparison keywords working properly.

 

The problem:

 

The gte_date keyword seems completely non-functional for me no matter what combinations I use. Simple or complex. The default format for my asset list is as follows:
 

%begin_asset_metadata_PublishedDateOverride^date_format:Y-m-d^replace_keywords:gte_date:{globals_date^date_format:Y-m-d}% 
    <div class="event %asset_metadata_Type% mix">
        <div class="details">
            <p>
                %asset_metadata_PublishedDateOverride^date_format:d M Y%<br/>
                %globals_date^date_format:d M Y%
            %begin_asset_metadata_DateRangeLabel%
                <i class="fa fa-calendar">%asset_metadata_DateRangeLabel%</i> 
                <br>
            %end_asset_metadata_DateRangeLabel%
            %begin_asset_metadata_TimeLabel%
               <i class="fa fa-clock-o"></i> %asset_metadata_TimeLabel%</p>
            %end_asset_metadata_TimeLabel%
        </div>
        <div class="description">
            <h2>%asset_name_linked_to_link_url%</h2>
            %asset_attribute_summary%
        </div>
    </div>
%end_asset_metadata_PublishedDateOverride^date_format:Y-m-d^replace_keywords:gte_date:{globals_date^date_format:Y-m-d}% 

PublishedDateOverride is a Date metadata field that users can set themselves (and defaults to asset_published_date if not set).

Actual output:

All items are being printed currently regardless of their date :(

I have tinkered with the above by even reducing it to a simple

%begin_asset_published^lte_date:{globals_date}%
stuff
%end_asset_published^lte_date:{globals_date}%

to no avail.

Solutions?:

My asset list is set up and working fine as intended, this conditional is stumping me though to only showing future dated items. I may be thinking about this the wrong way however. It's unfortunate that the person who initially set up the site used News Items rather than Calendar Events, as I can't really change it at this point with so many future events in the format of a News Item :(

 

Happy to provide more info as needed

Misc. Info:
Squiz Matrix v5.3.4.0 (should be fine to use the date comparison keyword?)

Chrome Version 52.0.2743.116 (64-bit)

OSX 10.11.6

 


(Peter McLeod) #2

Hi

 

The actual date comparison modifers work fine - but I think it is the combination with the begin/else/end conditions is the issue - not sure why this is, I couldn't get it to work either using the same version of matrix.

 

Something ike below will output correctly:

%asset_metadata_PublishedDateOverride^replace_keywords:gte_date:{globals_date}:
   <p>{asset_name} is a future event</p>
:
   <p>{asset_name} is a past event</p>
%

But would get a bit messy if you have other nested logic. Though using: {asset_metadata_<fieldname>^tagif:span class="something"} might work to wrap content in tags in they are available.

 

A couple of other options:

 

You could use the listing to create an array of data and use a Rest Javascript asset to process it (with whatever logic you need to apply - using server side JS) and output html (

 

Alernatively, if you wanted to automate creating event assets, you could look into using the Javasrcipt API. We often use it for setup and maintenance work. For example, you could write script that would iterate over an array of ids (of the standard pages), get the various attributes/metadata to copy, create the single calendar events and set the attributes / metadata to it. A bit of setup and testing would be required though.

 

Thanks

Peter


(James Porich) #3

Thanks Peter,
I'll check this one out soon. Using the Javascript API would be something to look in to as far as converting over to Single Calendar Event assets.

I figure these guys will need to do it sooner or later, if I could set that up properly that would solve a whole bunch of issues  :rolleyes:

 

Cheers