EasyCFM.COM ColdFusion Forums / Coding Help! / Dynamic text based on URL

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Dynamic text based on URL

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

][ce
07-05-2003 @ 9:41 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Jul 2003

Hello everybody!

I'm running into a small road block, and any help would be greatly appreciated!  Here is my dilemma:

I have a web site which includes approximately 150 cfm pages.  Each page has a "generic" navigation menu found on the left hand side.  Here's the thing; currently, the menu is static, whereas the code is actually written in every page, and not called from one generic file using CFINCLUDE.

I have done this because I changed the CLASS type from "LeftMenu" to "LeftMenuDisabled" if the user is viewing that particular page, which disables the link and changes the color, in order to flag it as being the current page.

As you can imagine, this leads into quite a large task if an addition/removal of a link needs to be made.

So here's what I'm thinking; can the class be dependant on the current location of the user?  So, I would call the menu from one generic page, which would recognize the location and change the class type accordingly.

Again, any help would be greatly appreciated!

Thanks,
Dave

apletfx
07-05-2003 @ 10:29 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 607
Joined: Nov 2002

You might try something like this:

<cfif cgi.script_name IS "my_page.cfm">
<!--- if page currently on is true then deactivate link --->
<a href="linkname.cfm" class="LeftMenuDisabled">Link Name</a>
<cfelse>
<a href="linkname.cfm" class="LeftMenu">Link Name</a>
</cfif>


havent tested this, but I think it may get you going in the right direction.

Mark Aplet

=============================
Never settle with words what you can
Accomplish with a flame-thrower.
    - Bruce Feirstein
=============================

Webmaster
07-05-2003 @ 11:14 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

Actually, what Applet did was good, but has a few issues on it Smile

Try this instead:

<!--- if page currently on is true then deactivate link --->
   <a href="linkname.cfm" class="<cfif cgi.script_name IS "/my_page.cfm">LeftMenuDisabled<cfelse>LeftMenu</cfif>">Link Name</a>

I changed two things....

1) I combined the link and only made the class the condition (This way your page is smaller and loads faster.
2) cgi.script_name will return the path with the starting "/" so hat needs to be added to the check..

But that is the basic idea in mind... give it a shot... it should do what you need Smile

Thanks,
Pablo Varando

=====================================================

][ce
07-06-2003 @ 9:14 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Jul 2003

This is great!  It will definately help me out!Just one more question though... Smile

The code given is great when the condition is one particular page, although (and I didn't specify this in my earlier post, my bad...) the menu items on the left hand side are main groups.  Thus, each link may have 12-15 pages that would make it "LeftMenuDisabled".

Is there a way to have it change on a relative path directory, instead of one particular page?

Thanks again for your help!
Dave

apletfx
07-06-2003 @ 1:11 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 607
Joined: Nov 2002

If I understand you correctly, then you would need use the above code for each link that you wanted to check. That includes all sub links.

Just a thought... If you are already going back to revisit each page... then why not make one navigation menu and include it into each page. It would certianly be easier in the long run if you needed to make changes again.

Mark Aplet

=============================
Never settle with words what you can
Accomplish with a flame-thrower.
    - Bruce Feirstein
=============================

][ce
07-06-2003 @ 2:24 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Jul 2003

Yeah... that's what I was afraid of.  I didn't want to have to check against every page available, for each link.  It would make for many CFIF statments!

... and in response to your suggestion; this is exactly what I'm trying to do.  It definately would be a time saver, just a few bugs I need to work about before doing so.  Hence, this discussion topic Smile

So, just to confirm, there's no way I can have it check something like this:

<a href="linkname.cfm" class="<cfif cgi.script_name IS "/path/path/path/">LeftMenuDisabled<cfelse>LeftMenu</cfif>">Link Name</a>

... as opposed to defining every page?

Thanks again for all of your feedback, Pablo and Mark.  It looks like I'm almost there!
Dave


apletfx
07-06-2003 @ 2:30 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 607
Joined: Nov 2002

Well that is essentialy what you would be doing. Lets
say you create a sidenav.cfm and in it it would
contain a large list a <cfif> statements. Each link
would contain a cfif to check wether or not the
current page is to be linked or not... There is no
magic tag that can do it all for you. Atleast not that
I'm aware of. It may seam like a lot of work to change
it now, but if you do it now, it will save you alot of
time in the future.


=============================
Never settle with words what you can
Accomplish with a flame-thrower.
    - Bruce Feirstein
=============================

][ce
07-06-2003 @ 2:38 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Jul 2003

I understand what you are saying, but here's my only concern with this tactic; If I set up approx 150 cfif's, and then everything works, I don't have any issues with that.  Although, this would entail, that everytime I add another page, I will have to go back to this nav.cfm and update it with another cfif.

I was hoping that the cgi.script_name could recognize full paths, as opposed to single pages.  This way, I only insert 8 or 9 cfif's, and I don't have to worry about adding new pages, only new directories.

Does this make sense, or am I way out in left field?




Website Designed and Developed by Pablo Varando.