put a counting variable in my template, which goes over the different blocks in my content
whenever it is a heading I apply an id=$count to the heading
I save the heading and the ID in a file
So far so good. I end up with a file with all headings and corresponding IDs. I can then use the file and generate the drop down menu, probably via js .!?
But I now realized, that the file will be freshly generated each time the subpage is opened, which is maybe not ideal. So what I actually need is, when I change the page in the panel, then the file and IDs should be generated once and thats it. Can anyone point me to a description of what happens, when I save the panel, so I may figure out, where to sneak my php in. Or maybe someone has a better idea.
so any thoughts would be highly appreciated.
I only need it for one page, I just thought doing it on the fly each time generates too much overhead.
But that would of course make it much easier. I’ll try it out …
people are doing far worse stuff than this and are getting away with it.
If it really is too slow (but I’d bet it isn’t), you could consider caching the whole website: https://getkirby.com/docs/guide/cache before trying to optimize otherwise. Even if you save the ids in a file, you still would have to load that file and then “dynamically” generate the menu from that file.
You would be still doing the loops, but over a cache file instead of the loops over the content. Not much of a difference if you ask me.
ok so I got it to work faster than I thought. Since I’m using the Builder and in part nested Builders, it was a bit more complicated. The only thing I did not get to work was $block->hash() so I was falling back to my $count variable. So thi is how my navigation looks like now.
So it actually works quite well I just have to fiddle a bit more with the CSS, since it jumps a bit and is left aligned, probably because it is within the li element.
done, still looks really bad. Apparently tones of tabs coming from my editor. It is perfectly fine in Atom locally though. Anyway I essentially have no clue about php … unfortunately
A “slug” is a url safe representation of a text. So, for example, “Drei Säulen” becomes “drei-saulen” (or “drei-saeulen”, depending on config). With the editor plugin I thought you were using, ->hash() would have done this.
If the Builder plugin works like I think it does (I’ve never used it), you should be able to do it with the slug() field method.
@texnixe
ok so while I was at it, I was going over all my snippets and removed the echos, but I assume I did not invent that myself… I also put a snippet in
I also realized you not only formated my code (thanks!) but also edited it. In particular taking out the curly brackets from my if statements. As far as I have googled both is possible. Any particular reason why?