CODE

Show or hide content at a certain date/time

Sometimes you need to make a change to a page/module layout/module item content at some distant time in the future, or perhaps at an inconvenient time.

v1.0.0

For example a sale announcement on a page, a navigation update, or a new banner that appears at a certain time.

  1. Simply add your current content to the “This content is shown before the release time” section and the content you want to have displayed in the future in the “This content is shown after the release time” section.

    Then update the release_time with the time that you want your content to display. The time format should be in YYMMDDHHMM (HH should be in 24H) format.

    <!--Treehouse CODE v1.0.0-->
    {% assign current_time = "now" | date: "%y%m%d%H%M" | plus: 0 %}
    {% assign release_time = 2012181442 %}
    {% if current_time >= release_time %}
    This content is shown after the release time
    {% else %}
    This content is shown before the release time
    {% endif %}
  2. If you just had new content and no old content to replace you could eliminate the {% else %} portion of the script.

    <!--Treehouse CODE v1.0.0-->
    {% assign current_time = "now" | date: "%y%m%d%H%M" | plus: 0 %}
    {% assign release_time = 2012181442 %}
    {% if current_time >= release_time %}
    This content is shown after the release time
    {% endif %}
  3. You could also use this to show content every day at a specific time and hide it later on in the day. The following will show some content at 2pm and hide it at 4pm.

    <!--Treehouse CODE v1.0.0-->
    {% assign current_time = "now" | date: "%H%M" | plus: 0 %}
    {% assign release_time = 1400 %}
    {% assign withdraw_time = 1600 %}
    {% if current_time >= release_time and current_time <  withdraw_time %}
    This content is shown after the release time and before the withdraw time
    {% endif %}
  4. Or every week on a specific day. Note the day is three letters starting with a capital letter.

    <!--Treehouse CODE v1.0.0-->
    {% assign current_day = "now" | date: "%a"  %}
    {% assign release_day = "Mon" %}
    {% if current_day == release_day %}
    This content is shown on a specific day.
    {% endif %}

    Note on time zones: this release time is based on the time that the server is in. This can be determined by looking in your partner portal and clicking the pencil next to your site. You’ll see the time zone listed there. If you need to do a time zone adjustment, you can either do it manually by updating the release time, or for the first three examples you could add or subtract the adjustment in HHMM by adding or subtracting in the | plus: 0 portion i.e. if your server is in the Pacific Timezone, and you want the release to occur in the Easter Timezone (3 hours later), you could make it | plus: 300 (plus 3 hours and 00 minutes). So if you want the release to be at 9am PT, you set the release time to be 2012180900 and the | plus: 300, when it’s 6am at your server (or 6H 00M + 3H 00M), the release will be at 9am ET.

Comments or questions? Head over to the Treepl CMS forum to discuss with the community.