PDA

View Full Version : how would i show selected ona menu that is a file include?


jarv
07-29-2009, 09:04 AM
ok so I have file include menu.asp

<div id="navigation">
<ul>
<li><a href="#">home</a></li>
<li><a href="#">about us</a><li>
<li><a href="#">services</a><li>
<li><a href="#">clients</a><li>
<li><a href="#">portfolio</a><li>
<li><a href="#">contact</a></li>
</ul>
</div>


If I wanted to add a class to the li to the currently selected page, how would i go about doing this, someone told me to use request.servervariables?!

thanks

abduraooft
07-29-2009, 09:45 AM
You can do it using pure CSS (with some additions in your HTML), see http://www.codingforums.com/showpost.php?p=605564&postcount=3

Old Pedant
07-29-2009, 10:08 PM
Man, do I feel STUPID for not ever figuring out that trick! Thanks, abdurooft, even if it was just a re-post <grin/>.

He's right, you can do this an ASP (or ASP.NET) via Request.ServerVariables, and I've done that many times in the past, but this trick with the ID on the <body> is *SO* much more sensible!

abduraooft
07-30-2009, 08:24 AM
Now a days, I add a CSS file like
echo '<link type="text/css" rel="stylesheet" href="/css/style.php?page='.$page.'" media="screen">'; and in that style.php, I'll have something like
header("Content-type: text/css");
$page=$_GET['page'];
echo "#$page ul .$page{background:#E6C170;}";

Old Pedant
07-30-2009, 08:43 AM
Yeah, the ASP equivalent would be:

<link type="text/css" rel="stylesheet" href="/css/style.asp?page=<%=pageName%>" media="screen">

Or maybe, using the server variable:

<link type="text/css" rel="stylesheet" media="screen"
href="/css/style.asp?page=<%=Request.ServerVariables("URL")%>">


And then the "style.asp" page could be something like:

<%
Response.ContentType = "text/css"
page = Request("page")
' in case the URL is in a subdirectory, get just the file name.
' It's okay if there is no / in the URL...InStrRev will then return 0 and
' the +1 will mean that Mid gets all the characters of the string
page = Mid( page, InStrRev( page, "/" ) + 1 )
%>
#<%=page%> ul .<%=page%>{background:#E6C170;}


Fun stuff.