How can I “remember” a value such as using a parameter?
- This topic has 4 replies, 2 voices, and was last updated 3 months, 3 weeks ago by .
- March 22, 2021 at 7:14 pm #5429publii-slpa
I capture a value from this.items.length from
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!!March 31, 2021 at 7:42 pm #5507Tomasz Dziuda
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!April 3, 2021 at 1:30 am #5528publii-slpa
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!!April 5, 2021 at 6:12 pm #5541Tomasz 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!April 7, 2021 at 3:35 am #5558publii-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
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)
It all works now!
I am hoping my code helps inspire others.
- You must be logged in to reply to this topic.