Sign in

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

  • This topic has 4 replies, 2 voices, and was last updated 2 weeks, 2 days ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5429
    publii-slpa

    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
    Tomasz Dziuda

    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.? 🙂

    --
    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!

    #5528
    publii-slpa

    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
    Tomasz Dziuda

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

    --
    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!

    #5558
    publii-slpa

    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!!

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