I have a dynamically generated variable that contains the currently selected city by the user. The format of the string is exactly the same as the href in the navigation menu below except without the prefix /city/
.
Example:
$user_city = 'london';
$user_city = 'edinburgh';
...
I have the navigation menu below and I want to highlight the currently selected city, that is I want to add a class "active" to the currently selected city.
<ul>
<li class="first"><a href="/city/all">All</a></li>
<li><a href="/city/london">London</a></li>
<li><a href="/city/liverpool">Liverpool</a></li>
<li><a href="/city/edinburgh">Edinburgh</a></li>
<li class="last"><a href="/city/glasgow">Glasgow</a></li>
</ul>
I know I could achieve this by putting each list item into an if statement looking whether $user_city equals the string in the href attribute. But I guess there must be a much smarter way?
Thanks in advance