Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Use CGI Variables to Assign body ID

New Here ,
Jul 13, 2010 Jul 13, 2010

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.

904
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Jul 13, 2010 Jul 13, 2010

To stick with the function names I would say it would be more correct to describe it this way.

  1. The listLast() function looks at the cgi.script_name string as a list of elements separated by either forward or backward slash characters (\/) and returns the last item in the list.
  2. The listFirst() function loosk at the string returned by the listLast() function as a list of elements separated by the dot|period character (.) and returns the first item in the list.
  3. It then outputs this string, which happe
...
Translate
Valorous Hero ,
Jul 13, 2010 Jul 13, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2010 Jul 13, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 13, 2010 Jul 13, 2010

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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2010 Jul 13, 2010

That's exactly what I was looking for.

If I understand this snippet correctly....

  • It looks for the variable cgi.script_name
  • then truncates every thing preceeding and including the "/" and the "\"  -- I guess this accounts for the directory structure and the "http://"
  • then trundates everything after and including the "."
  • and finally outputs the resulting page name

Is this right?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 13, 2010 Jul 13, 2010

To stick with the function names I would say it would be more correct to describe it this way.

  1. The listLast() function looks at the cgi.script_name string as a list of elements separated by either forward or backward slash characters (\/) and returns the last item in the list.
  2. The listFirst() function loosk at the string returned by the listLast() function as a list of elements separated by the dot|period character (.) and returns the first item in the list.
  3. It then outputs this string, which happens to be a file|page name.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2010 Jul 13, 2010
LATEST

You've been a big help.  Thank you very much!


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources