2
You could fetch your entries then split them in three arrays which would give you the ability to then add headings manually and display as you need to.
{# Define today and three arrays to hold your grouped entries #}
{% set today = now|atom %}
{% set futureBids = [] %}
{% set currentBids = [] %}
{% set pastBids = [] %}
{# Fetch your entries #}
{% set ...
2
An empty date field will return null. Your conditional is slightly off as you have an elseif straight after your first if. Try:
{% if entry.eventStartDate is empty %}
There is no date set.
{% elseif entry.eventStartDate > now %}
There is a date and it's greater than now.
{% elseif entry.eventStartDate < now %}
There is a date and it's ...
2
You're looking for the toDateTime() method in the DateTimeHelper class:
DateTimeHelper::toDateTime($pubDate, true);
2
The special strings :empty: and :notempty: might be what you're looking for. The docs list it only against expiryDate, but I think it's available for any field: https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#expirydate
2
After trying multiple options found an answer:
2
String interpolation in Twig only works with double-quoted strings.
Change the .startDate line to .startDate(['and', ">= #{start}", "< #{end}"]) and it should work.
2
Here's an example value that will set it to today:
[
'timezone' => 'America/New_York',
'date' => date('m/d/Y')
]
As always, easiest to find out how it's done by inspecting the fields as they are saved in the control panel.
2
You could do this:
{# Your date 2020-11 in atom format e.g 2020-11-01T00:00:00+01:00 #}
{% set departureDate = craft.app.request.getParam('departure') | date("Y-m") | atom %}
{# Your date + 1 month in atom format e.g 2020-12-01T00:00:00+01:00 #}
{% set untilDate = departureDate | date_modify('+1 month') | atom %}
{# Query between those 2 dates #}
...
2
Date fields in Craft are returned as DateTime objects, so you need to convert these to a string to be able to compare them.
The best way of doing this is to use the yyyy-mm-dd format as this makes it is easy to compare dates.
So your comparison would become:
{% if (entry.dateUpdated|date('Y-m-d')) >= (entry.postDate|date('Y-m-d')) %}
Updated on {{...
2
What an idiot.
I almost never use Advanced element queries which is why it never popped into my head I guess.
So you can add where() and orWhere() into your standard craft.entries calls.
So my code becomes
{% if craft.app.request.getParam('departure') | length %}
{% for dept in craft.app.request.getParam('departure') %}
{% set lastDay = dept [0:7]...
1
Found it: the reason for the Exception is, that the dynamic method productStartDate (coming from the CustomFieldBehavior) needs an Array as parameter.
I have no clue why I get this misleading Exception though...
So finally, this works:
use craft\commerce\elements\Product;
$product = Product::find()
->type('ticket')
->...
1
You're not checking against a valid field there - try using entry.postDate instead of entry.post
1
You should be able to use the date string you get from your parametern without even editing it.
{% set entries = entries.startsOn(craft.app.request.getParam('departure')) %}
More information about querying on datefields can be found here: Date Fields | Craft CMS Documentation | 3.x
1
If you go to that user's account settings, then click on the "Preferences" tab, I'm guessing they have their "Formatting Locale" setting set to Cymraeg.
1
Having done some further testing and research I believe this is a case of having to merge two date objects and ensuring that these are set as date/time objects when merging them into a variable.
Here are some examples way:
{% set thisWeeksDayAndTime = thisWeeksDay|date() ~ ' ' ~ classStartTime|time() %}
{% set thisWeeksDay = page.startDate|date_modify('...
1
Perhaps you could use the Preparse Field plugin, so that you only need to deal with one field. That would make the query easier.
https://plugins.craftcms.com/preparse-field
1
I hope I am not completely missing the point, but I guess like that:
Initial 5:
{% for block in block.eventList.eventDate('>=' ~ (now|atom)).orderBy('eventDate asc').limit(5).all() %}
{{ block.eventTitle }}
{% endfor %}
rest:
{% for block in block.eventList.eventDate('>=' ~ (now|atom)).orderBy('eventDate asc').offset(5).all() %}
{{ ...
1
I solved that by adding a dropdown field to user profiles where I allowed users to select timezone and then in custom module set the selected timezone like this:
class SiteModule extends Module
{
public function __construct($id, $parent = null, array $config = [])
{
// Set correct Timezone
$currentUser = Craft::$app->getUser();
...
1
Used super sort plugin and got away with this:
{% for item in entries|supersort('sortAs', '{dateSet.first.startDate|date("c")}') %}
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
datetime × 233templating × 37
entries × 34
plugin-development × 20
postdate × 13
matrix × 12
timezone × 11
craft3 × 10
localization × 10
filter × 9
query × 9
archives × 9
entry × 8
ordering × 8
search × 6
events × 6
forloop × 6
custom-field × 6
queries × 6
field × 5
elementcriteriamodel × 5
language × 5
group × 5
control-panel × 4
database × 4