'Hugo Template eq Operation Not Functioning as Expected

I have a Hugo shortcode where I am checking the day of the week:

{{ $weekDay := now.Weekday }}
{{ if eq $weekDay "Monday" }}
    ...display content here...
{{ end }}

However, the $weekDay value, when it is Monday is not evaluating to true and the content within the if block is not being displayed.

When I do the following, the content is being displayed:

{{ $weekDay := now.Weekday }}
{{ if eq $weekDay now.Weekday }}
    ...display content here...
{{ end }}

The content in the if block is being displayed. Is the $weekDay variable not a string datatype?



Solution 1:[1]

As I suspected, the operands being compared were of two separate datatypes. Using the String property results in a comparison of two String datatypes:

{{ $weekDay := now.Weekday }}
{{ if eq $weekDay.String "Monday" }}
...
{{ end }}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 m2web