Copy link to clipboard
Copied
I'm trying to check if the month in a date (in format "MM") is <7 but the code only seems to be calculating for the {% else -%} part of the code. I've tried using brackets and no brackets but neither seem to work.
{% assign newMonth = globals.site.dateNow | date_add: 1, "month" -%}
{% assign newYear = globals.site.dateNow | "yyyy" -%}
{% assign newDay = "01" -%}
<p>newMonth : {{newMonth | date: "MM"}}</p>
{% if newMonth | date: "MM" | convert: "number" | json < 7 -%}
<p>Retrospective Date is: {{newDay}}-{{newMonth | date: "MM"}}-{{newYear | date_add: -3, "year" | date: "yyyy"}}</p>
{% else -%}
<p>Retrospective Date is: {{newDay}}-{{newMonth | date: "MM"}}-{{newYear | date_add: -2, "year" | date: "yyyy"}}</p>
{% endif -%}
I've never gotten reliable results using filters in an IF tag, and usually create a simple var to test prior to entering the IF.
Copy link to clipboard
Copied
I've never gotten reliable results using filters in an IF tag, and usually create a simple var to test prior to entering the IF.
Copy link to clipboard
Copied
I'd like to add in a text picker so I can run tests on various dates. I've got this far but can't get anything from the input field
Enter Date to test
<input name="test" id="test" class="cat_textbox" readonly="readonly" style="background-color: #f0f0f0;" onfocus="displayDatePicker('test');return false;" type="text" />
<h2>Fields that will be calculated (these will be hidden)</h2>
{% assign startDate = test.value | convert: "date" -%}
Is this possible in liquid or do I have to use javascript?
Copy link to clipboard
Copied
It depends on where the test is being run and what data is being used.
Liquid is a markup processing language - it's used to dynamically construct the page before it's sent to the user - only the server understands it (most of the time).
Once the page has been rendered and sent to the client's browser, liquid is out of the picture, and any logic performed at the browser needs to be done using standard web technology - javascript/jquery/angular/css/etc
Copy link to clipboard
Copied
THanks again - thats a good explanation.
Copy link to clipboard
Copied
Thanks! That did the trick