I'm trying to figure out how to send a specific message when the time is before or after a certain time.
I have a weekly recurring event (midday every Monday) and although I can vary messaging depending on the day of the week, I can't figure out how to go more granular and send different messaging depending on whether the current time is before or after midday on a certain day.
I'm struggling to find an answer because most logic is in relation to one single event (with a date and a time) whereas mine just needs to be in relation to a specific time that repeats once a week.
This is what I started off with:
{% assign today = 'now' | date: "%A" %}
{% assign time = 'now' | time_zone: ${time_zone} %}
{% case ‘today' %}
{% when 'Monday' %}
{% if hour < 12:00%}
Today's the big day!
{% if hour > 12:00%}
You have till next Monday
{% else %}
Default copy
{% endcase %}
But I'm definitely very far off, so I would love any help!
Thank you!
You're example is almost correct. You're missing some "endif" thus I suggest you to use some liquid aware IDE. I made an example that I hope it's clear enough you can adapt to your situation.
{% assign time = 'now' | time_zone: 'UTC' %}
{% assign today = time | date: "%A" %}
{% assign hour = time | date: "%H" %}
{% assign minute = time | date: "%M" %}
{% case today %}
{% when 'Monday' %}
{% if hour < "12" %}
It's Monday Morning!
{% if hour == "10" %}
{% if minute > "20" %}
It's between 10:20 and 10:59
{% endif %}
{% endif %}
{% else %}
It's Monday Afternoon!
{% endif %}
{% when 'Tuesday' %}
It's Tuesday
{% when 'Saturday' %}
{% when 'Sunday' %}
{% if hour < "12" %}
It's the weekend in the morning!
{% endif %}
{% else %}
{% if hour < "12" %}
It's another day in the morning
{% else %}
It's another day in the afternoon
{% endif %}
{% endcase %}
Related
I'm having an issue with a for loop in Shopify. I'm sure it used to work, but I can't get it to work over the number 9 now.
{% assign productTag1 = Availability14 %} (in this example, the product has only 1 tag, which is Availability14)
{% assign avail_stop = false %}
{% for j in (0..15) %}
{% assign check_avail = 'Availability' | append:j %}
{% if productTag1 contains check_avail %}
{% assign avail_stop = true %}
{% capture tag_name %}{{check_avail}}{% endcapture %}
{% break %}
{% endif %}
{% endfor %}
{% if avail_stop %}
{% assign availability = check_avail | remove:'Availability' | plus:0 %}
{% endif %}
At the moment, I'm returning 1, not 14. I imagine it's something to do with the fact 14 includes a 1, but I can't wrap my head around it.
Any help is appreciated.
You have a {% break %} statement in your if. Once the if becomes true it will exit the loop instantly.
If you want to skip the next code you must use {% continue %} not {% break %}.
On my mind this is an issue with conditional operator. As you said, 14 contains 1, so why not simply use strict conditional operator like this:
{% if productTag1 == check_avail %}
{% assign has_stop = true %}
{% break %}
{% endif %}
(or did I miss something?)
I’m building an ICO Website. The website contains a ‘coins’ collection, this collection contains all the ico coin pages. I have then created pages such as https://moonlandingnetwork.netlify.com/upcomingico , https://moonlandingnetwork.netlify.com/activeico etc to display these coins based on whether they are upcoming, active or ended. I used this code to filter these coins based on the date and based on whether the coin is featured.
{% assign featuredcoins = site.coins | where: ‘ico.featured’, ‘true’ %}
{% assign regularcoins = site.coins | where: ‘ico.featured’, ‘false’ %}
{% assign timeframe = 86400 %}
{% assign current_date = “now” | date: “%s” | minus: timeframe %}
{% assign featuredUpcoming = “” | split: ‘,’ %}
{% for coin in featuredcoins %}
{% assign pre_ico_end_date = coin.pre-ico.end-date | date: “%s” | plus: 0 %}
{% assign ico_start_date = coin.ico-detail.start-date | date: “%s” | plus: 0 %}
{% if current_date > pre_ico_end_date and ico_start_date > current_date %}
{% assign featuredUpcoming = featuredUpcoming | push: coin %}
{% endif %}
{% endfor %}
{% assign regularUpcoming = “” | split: ‘,’ %}
{% for coin in regularcoins %}
{% assign pre_ico_end_date = coin.pre-ico.end-date | date: “%s” | plus: 0 %}
{% assign ico_start_date = coin.ico-detail.start-date | date: “%s” | plus: 0 %}
{% if current_date > pre_ico_end_date and ico_start_date > current_date %}
{% assign regularUpcoming = regularUpcoming | push: coin %}
{% endif %}
{% endfor %}
{% for coin in featuredUpcoming limit: 2 %}
<li>Featured Coin</li>
{% endfor %}
{% for coin in regularUpcoming %}
<li>Regular Coin</li>
{% endfor %}
Where I’m stuck is I need to paginate this. I know jekyll doesn’t support pagination of collections. I came across Jekyll paginate V2, Octopress Paginate and this code https://gist.github.com/Phlow/5613fb3f18946f577f071e2a258749a3 in my research. But i couldn’t get any of those to work.
I also require the pagination to work in such a way that the featured coins change on each new page along with the regular coins. Can somebody help me direct on what i should do.
I'm trying to compare the current date with the date of the post in jekyll/liquid. If the current date is less than the date of the post, then I want to show the post title.
Here is my code so far:
<header class="announce-ticker">
<div class="container">
{% capture currentDate %}
{{ 'now' | date: '%s'}}
{% endcapture %}
{% assign eventCount = 0 %}
{% assign eventPosts = site.posts %}
{% for post in eventPosts %}
{% capture postDate %}
{{ post.date | date: '%s'}}
{% endcapture %}
{% if currentDate < postDate %}
{% post.title %}
{% assign eventCount = 1 %}
{% endif %}
{{ currentDate}}
{{ postDate }}
{% endfor %}
{% if eventCount == 0 %}
<p>No events</p>
{% endif %}
</div>
</header>
My problem is that it's not showing the post when it is greater than current date.
Any help would be appreciated. Thanks!
Future dated posts are not published by default. Basic way to enable them through command line is to use the future option:
jekyll serve --future
Alternatively, you can add the future parameter to your _config.yml:
future: true
More options in this article.
I am trying to create an archive page of posts from my website. What I would like is to be able to have a pages for each list of posts by month in this format:
www.mywebsite.com/2016/11 would display all posts for November 2016.
Can I have a page for each month I have posted that is dynamically created each time I post in a new month? I don't want to have to manually create a new page for each month.
I already can group posts by year like so:
<ul>
{% for post in site.posts %}
{% assign currentdate = post.date | date: "%Y" %}
{% if currentdate != date %}
<li id="y{{currentdate}}">{{ currentdate }}</li>
{% assign date = currentdate %}
{% endif %}
<li>{{ post.title }}</li>
{% endfor %}
</ul>
Thanks for any help.
You can modify your date filter to integrate the month, e.g. date: "%B %Y". That's what I used in a layout, with a separate <ul> for each month.
From documentation, month-only values for the date filter are:
%b: abbreviated month name.
%B: full month name.
%m: month of the year (01 - 12).
Complete loop:
<ul>
{% for post in site.posts %}
{% assign currentdate = post.date | date: "%B %Y" %}
{% if currentdate != date %}
<li id="y{{currentdate}}">{{ currentdate }}</li>
{% assign date = currentdate %}
{% endif %}
<li>{{ post.title }}</li>
{% endfor %}
</ul>
About generating the pages, AFAIK this can only be done through a plugin. If you can't use plugins, e.g. if you're hosting your pages on GitHub, the best you can do is to reduce your pages to a short YAML frontmatter relying on a layout, like in this answer.
Is there a way I can create a loop in Jekyll that shows only posts starting today and into the future in chronological order? I'm making a GitHub Pages site for a meetup group and I'm kinda stuck.
This code below can do the trick:
{% assign curDate = site.time | date: '%s' %}
{% for post in site.posts %}
{% assign postStartDate = post.date | date: '%s' %}
{% if postStartDate >= curDate %}
Post datas here
{% endif %}
{% endfor %}
But you will need to "build" your site every day as Github only updates when there is a push to your repository.