?
Solved

cfif URL = index then do this

Posted on 2009-02-17
14
Medium Priority
?
1,416 Views
Last Modified: 2012-05-06
hi all, what i would like to say is this... IF the URL is index.cfm THEN do this. i'm sort of making the code up as i go along because i really dont know much about coldfusion. am i way off?
<cfif IsDefined ('URL.index.cfm')>
<li class="active"><a href="index.cfm"><span>home</span></a></li>
<cfelse>
<li class="hover"><a href="index.cfm"><span>home</span></a></li>
</cfif>

Open in new window

0
Comment
Question by:bede123
  • 5
  • 3
  • 3
  • +2
14 Comments
 
LVL 19

Assisted Solution

by:erikTsomik
erikTsomik earned 400 total points
ID: 23661982
can you try something like this
<cfif FindNoCase (cgi.script_name,index.cfm) gt 0>
<li class="active"><a href="index.cfm"><span>home</span></a></li>
<cfelse>
<li class="hover"><a href="index.cfm"><span>home</span></a></li>
</cfif>

or pass additional parametr with url . Like this index.cfm?page=home
and then
<cfif URL.page EQ 'home'>
<li class="active"><a href="index.cfm"><span>home</span></a></li>
<cfelse>
<li class="hover"><a href="index.cfm"><span>home</span></a></li>
</cfif>

0
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 400 total points
ID: 23662014
<cfif IsDefined ('URL.index.cfm')>

probably won't work the way you think

url variables are set by the calling url ie: index.cfm?myVar=1

so

<cfif IsDefined ('URL.myVar')>
the variable is #url.myvar#
</cfif>

you might want to do something like this

<cfparam name="url.classType" default="">
<cfif URL.classType eq "active">
<li class="active"><a href="index.cfm"><span>home</span></a></li>
<a href="index.cfm?classType=active">Set Hover</a>
<cfelse>
<li class="hover"><a href="index.cfm"><span>home</span></a></li>

<a href="index.cfm?classType=active">Set Active</a>

</cfif>

you use cfparam to ensure the variable exists when it hasn't been passed in the url


0
 
LVL 18

Expert Comment

by:Plucka
ID: 23662687
<cfif find(cgi.script_name, 'index.cfm')>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Plucka
ID: 23662732
which is what erikTsomik posted, but he missed the quotes around index.cfm
0
 
LVL 1

Author Comment

by:bede123
ID: 23662964
hmm, not quite working yet....

i'm working on this one:

<cfif FindNoCase (cgi.script_name,'index.cfm') gt 0>
<li class="active"><a href="index.cfm"><span>home</span></a></li>
<cfelse>
<li class="hover"><a href="index.cfm"><span>home</span></a></li>
</cfif>

it doesnt seem to have any effect.


from lookig at this one:

<cfparam name="url.classType" default="">
<cfif URL.classType eq "active">
<li class="active"><a href="index.cfm"><span>home</span></a></li>
<a href="index.cfm?classType=active">Set Hover</a>
<cfelse>
<li class="hover"><a href="index.cfm"><span>home</span></a></li>

<a href="index.cfm?classType=active">Set Active</a>

</cfif>



what is this extra line for?  <a href="index.cfm?classType=active">Set Active</a> ive tried it with and without this but i cant get it to work.

0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 23662979
you must pass classType  with the url
0
 
LVL 1

Author Comment

by:bede123
ID: 23662994
?

index.cfm is the landing page so i dont kow how to get something into the url before something has been pressed/clicked on the page. also what is classtype?
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 23663073
pass as url variable
please post your code
0
 
LVL 1

Author Comment

by:bede123
ID: 23663139
ok so hee is the .cfm page & the CSS below it.

you'll see that all other links get there values from a query. its only the home button i.e. the index.cfm page that is constant.
<ul>
<cfif FindNoCase (cgi.script_name,'index.cfm') gt 0>
<li class="active"><a href="index.cfm"><span>home</span></a></li>
<cfelse>
<li class="hover"><a href="index.cfm"><span>home</span></a></li>
</cfif>
 
<cfoutput query="getCat">
<cfif getCat.category_ID EQ URL.category>
<!--- active tab --->
    <li class="active"><a href="results.cfm?category=#getCat.category_ID#&amp;producttype=mainline&amp;imagesonly=1"><SPAN>#getCat.catName#</SPAN></a></li>
<cfelse>
<!--- default tab --->
    <li><a href="results.cfm?category=#getCat.category_ID#&amp;producttype=mainline&amp;imagesonly=1"><span>#getCat.catName#</span></a></li>
</cfif>
</cfoutput>
</ul>
 
 
 
css:
#navmenu ul {
        margin:0;
        padding:0;
        list-style:none;
        width:100%;
        float:left;
        
}
 
#navmenu ul li {
        float:left;
                
}
 
#navmenu li a {
        text-decoration: none;
        color:#ffffff;
        float:left;
        background:url(../images/gifs/bluetab_right.gif) no-repeat top right;
}
 
#navmenu li a span {
        padding:0 1em;
        line-height:2.1em;
        background:url(../images/gifs/bluetab_left.gif) no-repeat top left;
        float:left;
}
 
#navmenu ul a:hover,
#navmenu ul li.active a {
        color: #FFFFFF;
        background:url(../images/gifs/redtab_right_hover.gif) no-repeat top right;
}
 
#navmenu ul a:hover span,
#navmenu ul li.active a span {
        background:url(../images/gifs/redtab_left_hover.gif) no-repeat top left;
}

Open in new window

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 23666515
is that working for you?

I suggest modifying the second part as shown below.  The isDefined() function protects you from an error in case there is no category= on the URL.

Also, only the li with the class needs to be in the <CFIF>  that way you don't have to keep the two links in sync - as there is only one link statement now.
<cfoutput query="getCat">
  <cfif isDefined("URL.category") and URL.category is getCat.category_ID>
    <li class="active">  <!--- active tab --->
  <cfelse>
    <li> <!--- default tab --->
  </cfif>
  <a href="results.cfm?category=#getCat.category_ID#&amp;producttype=mainline&amp;imagesonly=1"><span>#getCat.catName#</span></a>
  </li>
</cfoutput>

Open in new window

0
 
LVL 1

Author Comment

by:bede123
ID: 23668323
i'm reluctant to change the second bit because that's the only bit that's working at the moment. its the first bit that i don't seem able to get going. you'd think that would be the easiest bit.

all i want to do is IF we are on the index.cfm page THEN display the ACTIVE state.
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 1200 total points
ID: 23670635
Ok, regarding the second bit... test your code by removing the category from your URL, make sure you have that covered.  You don't want to crash and burn.

Regarding the first part...

This should work for you...
<cfif listLast(cgi.script_name,"/\") is "index.cfm">
   <li class="active">
<cfelse>
   <li class="hover">
</cfif>
  <a href="index.cfm"><span>home</span></a>
</li>

Also, the problem with the code you have is that you have the two parameters of FindNoCase backwards.   findNoCase(substring, string)
so it should be..

  FindNoCase ("index.cfm",cgi.script_name)

But before we settle, let me ask the question.   What happens if you're on index.cfm in a subfolder?   /index.cfm  or  /myAccount/index.cfm  
Are you only wanting to match the top level or any level?

 Ok, once your first part works, pop-in the code for the second part.  :)

0
 
LVL 1

Author Comment

by:bede123
ID: 23671041
ok IT WORKS!!!!!!

i have pasted all the code below. but it all seems to be working perfectly.

thanks very much for your help.

ref your question about subfolders, this is not important for me on this project, only top level.
<ul>
<cfif listLast(cgi.script_name,"/\") is "index.cfm">
   <li class="active">
<cfelse>
   <li class="hover">
</cfif>
  <a href="index.cfm"><span>home</span></a>
</li>
 
<cfoutput query="getCat">
<cfif isDefined("URL.category") and URL.category is getCat.category_ID>
<!--- active tab --->
    <li class="active"><a href="results.cfm?category=#getCat.category_ID#&amp;producttype=mainline&amp;imagesonly=1"><SPAN>#getCat.catName#</SPAN></a></li>
<cfelse>
<!--- default tab --->
    <li><a href="results.cfm?category=#getCat.category_ID#&amp;producttype=mainline&amp;imagesonly=1"><span>#getCat.catName#</span></a></li>
</cfif>
</cfoutput>
</ul>

Open in new window

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 23671108
That was for future reference, in case you add subfolders.

This will match the index.cfm file of any level (including within subfolders)

<cfif listLast(cgi.script_name,"/\") is "index.cfm">


This will match only the top level index.cfm

<cfif cgi.script_name is "/index.cfm">


You can leave it as is, no harm...
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question