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.

How can I “remember” a value such as using a parameter?

  • #5429
    Avatar photo[anonymous]

    I capture a value from this.items.length from

    {{#each items}}

    and I would like to “remember” this value for comparison in other areas of menu.hbs.

    Is there a way of setting a parameter with this value without messing up “this” from each items?

    I am trying to distinguish the first and last dropdown-items within a menu.

    If I can crack thus nut, I am done creating my custom template.

    Cheers!!

    #5507
    Avatar photo[anonymous]

    Hi,

    I suppose that it is also connected with: https://forum.getpublii.com/topic/need-help-capturing-the-first-and-subsequent-menu-items-of-a-dropdown-in-a-menu/

    Please consider using custom @data variables like: @index, @first or @last described in: https://handlebarsjs.com/api-reference/data-variables.html

    If it won’t help – did you consider using CSS selectors like last-child last-of-type etc.? 🙂

    #5528
    Avatar photo[anonymous]

    Yes it is related to https://forum.getpublii.com/topic/need-help-capturing-the-first-and-subsequent-menu-items-of-a-dropdown-in-a-menu/ and https://forum.getpublii.com/topic/what-am-i-missing/.

    The good news is, I have a solution. But the system did not allow me to post the code for a solution for others to follow. Can you help me on this?

    Thanks for the reply.

    Cheers!!

    #5541
    Avatar photo[anonymous]

    I suppose that your code contains some fragments which are treated as unsecure by our WAF :/

    #5558
    Avatar photo[anonymous]

    Are you saying your WAF did not like what it wiffed?

    Fortunately, there is another option so here it goes.

    In a nav menu

    home

    articles

    _article 1

    _article 2

    _article 3

    contact

    I needed to identify nav links that are not dropdowns (home, contact), the top of a dropdown (articles), the first and last dropdown items (article 1 and article 3).

    I used this.items.length and this.level for much of it, but I needed to remember this.items.length using a parameter before processing dropdown items.

    I wrote a helper and then modified the menu.hbs.

    Here is the code. (ugly of course)

    https://codepen.io/codepen-slpa/pen/VwPMZKV

    It all works now!

    I am hoping my code helps inspire others.

    Cheers!!