Skip to main content

Checking a subpage for content.

I am trying to check to see if a subpage that I am adding to my page has content before I add it. I have a section on my home page at massyrs.nationbuilder.com that I want to be hidden if there are no upcoming events so that the column doesn't take up space. I tried using this to no avail:

{% if "upcoming_events" != "" %}
    <div id="action_col_wrapper">
      <div id="action_col_2">
        <div id="events_feed">
          <h1><a href="events">Come to an Event</a></h1>
          {% subpage "events" with "upcoming_events" %}
        </div>
      </div>
    </div>
  {% endif %}

I've also tried: {% if "upcoming_events" %}, {% if calendar.events.events_upcoming != "" %}, {% if calendar.events.events_upcoming %}, {% if (subpage "events" with "upcoming_events") != "" %}, {% if (subpage "events" with "upcoming_events") %}

Thank you.

Official response from

Hi Keith,

You can do this using the "page.calendar.events_upcoming_count" page variable, to check to see if the number of upcoming events is greater than zero.

To achieve what you've proposed, your _upcoming_events.html Liquid partial might look something like this:

{% if page.calendar.events_upcoming_count > 0 %}
    <div id="action_col_wrapper">
      <div id="action_col_2">
        <div id="events_feed">

          {% for event in page.calendar.events_upcoming limit:2 offset:0 %}
               ... your event excerpt display code ...
          {% endfor %}

        </div>
      </div>
    </div>
{% endif %}

Since the logic to check if events exist are within the partial template, you can simply call it on the home page like so:

{% subpage "events" with "upcoming_events" %}

Share this post

Showing 2 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.