Skip to content

Instantly share code, notes, and snippets.

@su-narthur
Last active March 6, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save su-narthur/93481ca989f034f62d71ca9c5eda765a to your computer and use it in GitHub Desktop.
Save su-narthur/93481ca989f034f62d71ca9c5eda765a to your computer and use it in GitHub Desktop.
{% set getParamDateFormat = "Y-n-j" %}
{% set today = "now"|date(getParamDateFormat) %}
{% set devotionalDate = ( su.request.query.date ) ? su.request.query.date : today %}
{% set dateFragment = devotionalDate|date("-m-d") %}
{% set devotional = su.collection( "devotionals" ).sort( "date", "desc" ).date("%"~dateFragment).limit(1).find()[0] %}
{% set displayDate = devotionalDate|date("l, F j, Y") %}
<div class="devotional">
<h3>{{ (devotional.title) ? devotional.title : "Devotional for "~displayDate }}</h3>
<div class="devotional-date">{{ displayDate }}</div>
{% set hasBy = devotional.by.first or devotional.by.last %}
{% set hasSource = devotional.source is not empty %}
{% if hasBy or hasSource %}
{% set byLine = (hasSource) ? "From "~devotional.source : "" %}
{% set byIntro = (hasSource) ? " by " : "By " %}
{% set byLine = (hasBy) ? byLine~byIntro~devotional.by.first~" "~devotional.by.last : byLine %}
<div class="devotional-source">
{{ byLine|raw }}
</div>
{% endif %}
<br />
<div class="devotional-content">
{% if devotional %}
{{ devotional.content|raw|nl2br }}
{% else %}
No devotional has been added for this date.
{% endif %}
</div>
<br />
{% set secondsInDay = 60 * 60 * 24 %}
{% set previousDate = ( devotionalDate|date("U") - secondsInDay )|date(getParamDateFormat) %}
{% set nextDate = ( devotionalDate|date("U") + secondsInDay )|date(getParamDateFormat) %}
{% set path = su.request.path|split("?")[0] %}
{% set previousUrl = path~"?date="~previousDate %}
{% set nextUrl = path~"?date="~nextDate %}
<a href="{{ previousUrl }}">Previous</a>
{% if devotionalDate != today %}
| <a href="{{ path }}">Today</a> | <a href="{{ nextUrl }}">Next</a>
{% endif %}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment