With regard to the use of "template inheritance" in the background, what does the navigation highlight do after the navigation bar of the foreground page is organized into a head file?

1. Home page. Html navigation section:

<ul class="dh">
    <li class="act"><a href=""></a></li>
    <li><a href""></a></li>
    <li><a href""></a></li>
    <li><a href""></a></li>
</ul>

2.
< ul class= "dh" >

navigation section of the list page.
    <li><a href=""></a></li>
    <li class="act"><a href""></a></li>
    <li><a href""></a></li>
    <li><a href""></a></li>
</ul>

.

after several pages are sent to the background, the background uses template inheritance to organize the navigation file into a head.html file, and then introduce this file into the navigation part of each page.
so that the navigation code for each page becomes the same.
for the time being, when I enter the onload of each page, I get the url, of the page to determine which page it is based on the url and then give it a highlight class.
but it"s troublesome to have too many pages
is there a better and more correct way to ask?

Dec.10,2021
The

menu is hierarchical, so no matter which page you are currently visiting, you can get the top-level menu (level 2, level 3, etc.).
take the top-level menu as an example:
cycle through all the top-level menus, and add a selected class when you cycle to the top-level menu id of the current access page.


since the template is used in the background, let the backend decide whether to add the act class


$url= $_ SERVER ['HTTP_HOST'] in the template according to the route. / / get the current url
< ul class= "dh" class= "> / whether to highlight according to the acquired path with php code in class

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36123-343af.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36123-343af.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?