1
votes

Using the admin panel on Orchard CMS I've created the following:

  1. A content type called CalendarEvent, it contains several fields including the EventDate;
  2. A query that has 2 filters, one by the content type (= CalendarEvent) and another one based on the date of the event. The Display Mode on the Layout is set to Properties;
  3. A projection to display the query when a menu item is clicked.

The problem is that based on the EventDate we only display upcoming events, not the ones in the past. If for some reason there are no events to be displayed, all the user gets is an empty page with no information whatsoever.

My question is, how can I modify my query or projection in order to display something like: "There are no current events scheduled"?

I know the Properties on the Query's Layout allow me to specify a "No Result", but this implies that a record is present and that the actual property is empty. However, in my example, no record is present.

Thank you all in advance.

Rafael

By the way, I am using the latest Orchard version 1.6.

2
By the way, I am using the latest Orchard version 1.6.Medeiros

2 Answers

0
votes

What I have done is to create a shape and use it as a view in my query. The shape will then have an if statement to check if the query return gives any results.

Example:

@using Orchard.ContentManagement
@using Orchard.Utility.Extensions

@{
    var dealsTerms = ((IEnumerable<ContentItem>)Model.ContentItems).ToList();
}
@if (dealsTerms.Any() )
{
    <div>
        @foreach (var dealTerm in dealsTerms)
        {
            var contentManager = dealTerm.ContentManager;
            <div>
                @Display(contentManager.BuildDisplay(dealTerm, "Summary"))
            </div>
        }
    </div>
}
else
{
   <p>No deals found</p>
}

I used this article as reference: http://www.ideliverable.com/blog/ways-to-render-lists-of-things

Good luck

0
votes

If your projections are Layouts elements, you can create a Projection.cshtml file in your theme's Views/Elements folder with the following:

@{
    var list = Model.List;
    var pager = Model.Pager;

    if (list != null)
    {
        @Display(list)

        if (list.Items.Count == 0)
        {
            <div>There are currently no items.</div>
        }
    }

    if (pager != null)
    {
        @Display(pager)
    }
}

This is a copy of the default template with the if (list.Items.Count == 0) section added. Edit as needed.