mysterious-toddler-20573
02/26/2022, 4:21 PMnarrow-lifeguard-9228
02/26/2022, 4:22 PMmysterious-toddler-20573
02/26/2022, 4:22 PMbulky-painting-16931
02/26/2022, 6:53 PMwhite-lion-11770
02/26/2022, 7:11 PMhx-swap-oob and I tried that too, which works great for the first click on a nav-link. It swaps in our html with the added .active class as expected, and we have styled it with a different color so that it shows this is the page the user is currently on. So far so good. However, the issue presents itself if we now click on another nav-link to navigate to a different page. We add the class to this new nav link, as we should, but the class is still remaining on the previous one. So now we have 2 highlighted nav links. So basically, there needs to be a way to remove it from the previous nav link, as well. Or perhaps, toggle it.
@User provided me with some useful links and the hyperscript take command looks like it can be used for accomplishing this.bland-coat-6833
02/26/2022, 7:12 PMhx-boost check hrefs and add an .active class or something to any links that match?white-lion-11770
02/26/2022, 7:15 PMwhite-lion-11770
02/26/2022, 7:16 PMgorgeous-airport-54386
02/26/2022, 8:50 PMbland-coat-6833
02/26/2022, 9:06 PMwhite-lion-11770
02/26/2022, 9:58 PMbulky-painting-16931
02/27/2022, 9:04 AMbulky-painting-16931
02/27/2022, 9:04 AMbulky-painting-16931
02/27/2022, 9:07 AMbland-coat-6833
02/27/2022, 9:46 AMbulky-painting-16931
02/27/2022, 9:50 AMgorgeous-airport-54386
02/27/2022, 9:51 AMbulky-painting-16931
02/27/2022, 9:51 AMbulky-painting-16931
02/27/2022, 9:53 AMwhite-lion-11770
02/27/2022, 10:00 AMa[up-history="true] on the nav-links to update the browser URL field to the html containing the new content. We only grab a specified fragment (#div) from the html but the template contains all the necessary Jinja {% includes... %} statements to rebuild the whole page in case of a refresh. up-current is automatically added to the correct nav-link by Unpoly, which is decided by the current browser URL, and highlights the correct page.
Not sure if that answers your question so please elaborate if I completely misunderstood what you meant :pbland-coat-6833
02/27/2022, 10:18 AMbland-coat-6833
02/27/2022, 10:20 AMbland-coat-6833
02/27/2022, 10:22 AMwhite-lion-11770
02/27/2022, 10:33 AM{% includes nav.html %}
- pulls in the main content e.g. {% block main-content %}
- the main-content block contains a div fragment to be used as a nav-link target
nav.html
- contains the nav links
- the nav links contain the spice to pull in a fragment from the href and put it in the target.
- the nav links also update the browser url, to let up-current know which page it is on, and in case of a page refresh
nav-link-1.html
- contains {% extends base.html %} in case of page refresh
- contains {% block main-content %} to be pulled in to base.html
- the main-content block contains a div fragment to be used as a nav-link targetwhite-lion-11770
02/27/2022, 10:41 AMbland-coat-6833
02/27/2022, 11:57 AMeager-autumn-92984
02/27/2022, 12:47 PMmysterious-toddler-20573
02/27/2022, 3:40 PMmysterious-toddler-20573
02/27/2022, 3:40 PMhtmx.onLoad() for adding js functionality to elements added dynamically