From 8637cf6add0b5be32dd58992e94d23ff1e80966c Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Mon, 25 Jun 2018 15:24:19 +0100 Subject: Simplify hiding navigation items slightly The code is now a bit longer, but it's also a bit clearer. The resulting HTML is also clearer. --- html/@include.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'html/@include.php') diff --git a/html/@include.php b/html/@include.php index 2cf50d3..3966ec0 100644 --- a/html/@include.php +++ b/html/@include.php @@ -26,11 +26,16 @@ function site_head($title) { function site_navitem($url, $text, $hide = false) { $selected = $url == $_SERVER['REQUEST_URI']; - $hbeg = $hide && !$selected ? '!--' : ''; - $hend = $hide && !$selected ? '--' : ''; - $sel = $selected ? ' class="selected"' : ''; + $classes = []; + if ($selected) { + $classes[] = "selected"; + } + if ($hide && !$selected) { + $classes[] = "hidden"; + } + $classes = count($classes) > 0 ? (" class=\"" . implode(" ", $classes) . "\"") : ""; - return "<{$hbeg}li{$sel}>{$text}"; + return "{$text}"; } /// Get the standard page header elements for the site -- cgit v1.2.1