Developer forum

Forum » Templates » RenderItemList - filter on date

RenderItemList - filter on date

Claus Kølbæk
Claus Kølbæk
Reply

Hey

Swift uses the RenderItemList, and I need to add a filter on it to ignore items which have a publish time set in the future, which works by adding this filter:

string filter = "PublishTime is before " + DateTime.Now.ToString("yyyy-MM-dd");
However, I would also like it to not filter out any where the date is unset or equal to DateTime.MinValue. - how do I achieve this? The documentation on the wording needed for the filter seems to have been lost in an update :)

For reference sake:  If I do it directly in the ItemPublisher template, it looks like this: ".Where(x => x.GetDate("ItemPublisher:Item.PublishTime") == DateTime.MinValue || x.GetDate("ItemPublisher:Item.PublishTime") < DateTime.Now)", however - at this point it has already applied the before mentioned filter, so it is ofc. to late to add it here.

(Code just fyi):

@RenderItemList(new {
    ItemType = itemType,
    ListTemplate = "ItemPublisher/List/" + listTemplate + ".cshtml",
    ItemFieldsList = "*",
    ListSourceType = "Page",
    ListSourcePage = listSource,
    ListPageSize = maxItemsInList,
    IncludeParagraphItems = false,
    ListOrderBy = listOrderBy,
    ListSecondOrderBy = listOrderBySecond,
    ListOrderByDirection = articleListSortOrder,
    Filter = filter
})


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Claus

The full docs is here: https://doc.dynamicweb.com/documentation-9/content/apps/item-publisher

A workaround is to run a SQL against the items and set the PublishTime to something in the past if the field is null. Maybe use a schedule to do it.

Another more comprehensive workaround is to use an index and the querypublisher. Then you can build your query using that.

BR Nicolai

 
Claus Kølbæk
Claus Kølbæk
Reply

There are plenty of workarounds ofc. - I can also do it with page services and so on, but I was kinda hoping on not having to redo the entire thing :)

The page you link to does have some some documentation, but it is mainly for querystring parameters and not for the filter. The only documentation I can see for the filter is this example:  Filter = "Areas contains \""+areaId+"\""

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

The querysring parameters are the same you pass to the filter....

 
Claus Kølbæk
Claus Kølbæk
Reply

"PublishTime is before ",  "Areas contains \""+areaId+"\"" are worded filters, not querystring parameters as I see it, or else I am just not understanding it? :)

if it had been the same shouldn't it have been Areas=*areaId* instead of Areas contains \""+areaId+"\"? in the example.

 

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Claus
Looks like we forgot to add 'is empty' operator for that feature!
I will register a task to support it.

Best regards,
Vladimir

Votes for this answer: 1

 

You must be logged in to post in the forum