ASP Variables passed to include (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


BobbyDouglas -> ASP Variables passed to include (2/6/2008 2:34:56)

I have an ASP page with the following include:

<!-- #include virtual="/_includes/main_nav.inc.asp" -->


main_nav.inc.asp contains:

<ul>
    <li><a href="/About-Us/">About Us</a></li>
    <li><a href="/Contact-Us/">ContactUs</a></li>
</ul>


When I use the include on the About Us page, the code displayed should be:

<ul>
    <li class="on"><a href="/About-Us/">About Us</a></li>
    <li><a href="/Contact-Us/">ContactUs</a></li>
</ul>


What's the best way to do this?

Using PHP, I can accomplish this using:

<?php $on="About Us"; include("/_includes/main_nav.inc.php"); ?>


Where main_nav.inc.php looks like:

<ul>
    <li<? if($page_on=="About Us"){ echo class="on"; }?>><a href="/About-Us/">About Us</a></li>
    <li><a href="/Contact-Us/">ContactUs</a></li>
</ul>


Basically, the About Us page will only have the class="on" when the include file contains a variable named $page_on that is equal to "About Us"

Also, if it makes a difference, maybe I ASP has a way to grab the folder name, and check if folder name == "About-Us"




rdouglass -> RE: ASP Variables passed to include (2/6/2008 8:36:18)

quote:

<li<? if($page_on=="About Us"){ echo class="on"; }?>><a href="/About-Us/">About Us</a></li>


One way in ASP is to do something like this:

<li<%IF Instr(Request.Servervariables("URL"),"About-Us") > 0 Then%> class="on"<%End If%>><a href="/About-Us/">About Us</a></li>

Instr looks for the string "About-Us" in the URL returned by Request.servervariables("URL")

That help any?




BobbyDouglas -> RE: ASP Variables passed to include (2/6/2008 11:22:08)

Roger,

When I try that, I believe the value of
Request.Servervariables("URL")
is actually the location of the include file, and not the end file, such as the About Us.




rdouglass -> RE: ASP Variables passed to include (2/6/2008 12:55:02)

Have you tried it? It doesn't for me. It returns what's in the address bar minus the domain and any querystring data) for me anyways.




Spooky -> RE: ASP Variables passed to include (2/6/2008 13:37:10)

The way Roger did it is what Ive used in the past.

Another way is to use server.execute if you have different asp nav pages (although it is longer :-)
If pagename="nav" then
Server.Execute("/_includes/main_nav.inc.asp") 
elseif If pagename="home" then
Server.Execute("/_includes/main_hm.inc.asp") 
End if


Just to expand on what Roger did, set your page name as a variable first :

<%
pagename = lcase(Request.Servervariables("URL"))
%>

<!-- #include virtual="/_includes/main_nav.inc.asp" -->

<li<%IF lcase(Instr(pagename,"about-us")) > 0 Then%> class="on"<%End If%>><a href="/About-Us/">About Us</a></li> 




BobbyDouglas -> RE: ASP Variables passed to include (2/6/2008 15:00:53)

Don't know why but it is working now, must have overlooked something before.

Thanks guys!

This is a powerful way to handle navigation for pages :)




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875