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.

[Handlebar] if value then…

  • #9254
    Avatar photo[anonymous]
    Goal: Output the last 3 posts of a keyword. Depending on the post, a different value should be output in the template (other css classes).
    
    Is there an easy way to do this? 
    
    Alternatively, I could repeat the code in the template and output only one entry at a time (with offset). But that would not be a nice solution.
    
    Thanks a lot!
    {{#getPostsByTags "count=3&tag_as=id&tags=1&offset=0&orderby=createdAt&ordering=desc"}}
    
    {{if @index = 0}}
    aaaaa
    {{/if}}
    {if @index = 1}}
    bbbbb
    {{/if}}
    {if @index = 2}}
    cccc
    {{/if}}
    
    {{/getPostsByTags}}
    #9255
    Avatar photoBob
    [anonymous] wrote:

    Output the last 3 posts of a keyword. Depending on the post, a different value should be output in the template (other css classes).

    Are you talking about three post pages or a list of three posts?

    #9256
    Avatar photo[anonymous]

    A list of three entries on a page (home page). a preview (title, excerpt, image) or overview.

    Exact description of what I want to do. In the template the entries are to be faded in one after the other with a time delay to create a kind of small animation. For this the “delay” must be entered in the template.

    Entry 1: x-transition.duration.800ms.delay.200ms
    Entry 2: x-transition.duration.800ms.delay.600ms
    Entry 3: x-transition.duration.800ms.delay.1000ms

    #9257
    Avatar photoBob

    A’ight, use the match helper  https://getpublii.com/dev/math-helper/

    e.g. the code below will generate the following CSS classes: delay-1, delay-2, delay-3….

    {{#each posts}}
       <article class="feed__item delay-{{math @index '+' 1}}" >
            <header>...
    #9263
    Avatar photo[anonymous]

    Thank you very much! So it worked well for my case.

    Because I didn’t want to set a class, some code or a number, I had to go a workaround.

    {{#if @index}}
                                    {{#if @last}}
                                        x-transition.duration.800ms.delay.{{math @index '*' 1000}}ms
                                    {{else}}
                                        x-transition.duration.800ms.delay.{{math @index '*' 600}}ms
                                    {{/if}}
                                {{else}}
                                    x-transition.duration.800ms.delay.200ms
                                {{/if}}
    #9317
    Avatar photo[anonymous]
    I have just seen that it is much easier with the {{#checkIf}} helper:
    https://getpublii.com/dev/checkif-helper/
    
    
    {{#checkIf @index '==' 0}}
    x-transition.duration.800ms.delay.200ms
    {{/checkIf}}
    {{#checkIf @index '==' 1}}
    x-transition.duration.800ms.delay.600ms
    {{/checkIf}}
    {{#checkIf @index '==' 2}}
    x-transition.duration.800ms.delay.1000ms
    {{/checkIf}}