Copy link to clipboard
Copied
I need help with a dynamic way to assign an ID to the body tag on static CFM pages.
I've been doing this manually, and was hoping to be able to do it with the cgi.SCRIPT_NAME variable. The problem is the ".cfm" gets included in the variable name. Also, if the page is in a sub-directory, the path also gets included.
I'd like to be able to dynamically at the page name, truncating the extension and path. Is this possible in CF8/CF9? Any help would be greatly appreciated.
To stick with the function names I would say it would be more correct to describe it this way.
Copy link to clipboard
Copied
And CF 7, 6, 5, and 4.5. Earlier then that is before my time.
Take a look at the list manipulation functions.
What you want to do can be very easily done with a combonation of the listLast() and ListFirst() functions.
You may want to also want to look at the system functions, there maybe one there that would work better for you then the cgi.script_name. Though there is really nothing wrong with cgi-script_name.
Copy link to clipboard
Copied
Thanks for your prompt reply, Ian. And thank you for the introduction to list functions and system functions -- I spend about 90% of my time in HTML/CSS, so this is new to me - so new that I'm not even certain what to do with them. I guess a better question would have been how to truncate the ".cfm" and the preceeding path name from the SCRIPT_NAME variable.
Are you suggesting that I should use the listLast() and listFirst() functions for the purpose of truncation, or is there something else I'm missing?
Copy link to clipboard
Copied
somecallmejosh wrote:
Are you suggesting that I should use the listLast() and listFirst() functions for the purpose of truncation, or is there something else I'm missing?
Yup, that is exactly what I am suggesting. ListFirst() returns the first element from a text string delimited by one or more characters, such as a dot [.] and ListList() returns the last element from a text string deliminted by one or more characters such as a [\/].
So you might want so see what something like this returns.
<cfoutput>#listFirst(listLast(cgi.script_name,"/\"),".")#</cfoutput>
Copy link to clipboard
Copied
That's exactly what I was looking for.
If I understand this snippet correctly....
Is this right?
Copy link to clipboard
Copied
To stick with the function names I would say it would be more correct to describe it this way.
Copy link to clipboard
Copied
You've been a big help. Thank you very much!