Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Little trick code

  • #923
    Avatar photo[anonymous]

    `{{#checkIf {{date createdAt ‘YYYYMM’}} > 201810}} NEW {{/checkIf}}`

    How can i make this code to work?

    #927
    Avatar photo[anonymous]

    Hi,

    I think that it is a bad idea by default to use handlebars to handle the NEW badge, because it causes that if your website won’t be updated forย  a long time, the very old posts will be marked as “NEW”.

    Please consider such case:

    1. Add to your post items attribute e.g. data-publish-date – put on this attribute date attribute: https://getpublii.com/dev/date-helper/
    2. The attribute should contain date timestamp – you can achieve this using “x” as a date format: https://momentjs.com/docs/#/parsing/string-format/
    3. Then create a script which will compare date timestamp and for posts newer than e.g. 2 weeks will add the “NEW” badge

    ๐Ÿ™‚

    #928
    Avatar photo[anonymous]

    Thanks ๐Ÿ™‚ But I like a simple solution within the Publii codes. You don’t know how to solve my line of code? Because it doesn’t work…

    #929
    Avatar photo[anonymous]

    Basically I’m just wondering if i can use {{date}} within {{#checkIf}} .ย  Is that possible and how?

    #930
    Avatar photo[anonymous]

    If you want to solve it via Handlebars:

    You can try if

    `{{#checkIf (date createdAt ‘YYYYMM’) > 201810}} NEW {{/checkIf}}`

    will work (it uses subexpression), but I suppose that it won’t as date helper will return string, not number.

    In my opinion you will have to create a custom helper – in my opinion there is no other way to achieve this.

    #931
    Avatar photo[anonymous]

    Thank you, but doesnt work… hmmm

    #932
    Avatar photo[anonymous]

    As I wrote – the only solution is creating custom helper under helpers.js.