Sign in

Little trick code

  • This topic has 6 replies, 2 voices, and was last updated 1 year, 3 months ago by .
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #923
    shorty

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

    How can i make this code to work?

    #927
    Tomasz Dziuda
    Moderator

    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

    🙂

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

    #928
    shorty

    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
    shorty

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

    #930
    Tomasz Dziuda
    Moderator

    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.

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

    #931
    shorty

    Thank you, but doesnt work… hmmm

    #932
    Tomasz Dziuda
    Moderator

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

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.