Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > ColdFusion

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 27 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2009, 04:38 PM   PM User | #1
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
cfincludes

hey, i'm stuck having to use coldfusion on a project. never touched it before. how to i set the cfinclude path so i don't have to add the relative path to the included file from page to page .. ../ ../../... in php u can just set a variable like mysiteroot and just add it to the beginning of the path... however in this case i don't know what the site root will end up being. also, is it fine just just add the .cfm extension to my page and use the cfinclude thing or do i need to add other cfml tags to make it work.
wyclef is offline   Reply With Quote
Old 11-08-2009, 06:55 AM   PM User | #2
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Hey,

#1, ColdFusion is awesome Much easier / straightforward than php (in my humble opinion ).

#2, by using the path '/' in a cfinclude, this should take you directly to the web root of the current web site. That is, there is no need to set up any variables or anything. So whatever your site root turns out to be, that is what '/' will turn out to be.

Examples:
Code:
<cfinclude template="/someDocInWebRoot.cfm">

<cfinclude template="/folderInWebRoot/docInFolder.cfm">
#3, It's ok to just add the .cfm extension to any file. There is no cfml markup required. Just like the php engine searches for <?php and ?> tags, the ColdFusion engine will search for any cf tags for processing, and if there are none, will just return the text of the document as-is.

Hope that helps. Btw, if you have any other questions, post again in this thread. Coding Forums doesn't send out a notification email that there is a new thread until 1am each day, but now that I'm subscribed to the thread, I'll get an email right away and help you out.

-Greg
Gjslick is offline   Reply With Quote
Old 11-08-2009, 03:38 PM   PM User | #3
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
right, the problem here is that the site will be housed in some subdirectory... so if i put the includes folder in .../folder/subfolder/includes and i have no clue what folder and subfolder will be named putting a / in front of the path won't help. that's why i thought if i could set up a global variable for the site root it would be easy to change once the site goes live. also, how does one handle changing content within an include file such as a title tag. i'd like to include the entire header but the title tag changes from page to page.
wyclef is offline   Reply With Quote
Old 11-08-2009, 07:27 PM   PM User | #4
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Ok, I see what you're trying to do. You have a few options.

1) You could create a mapping to your includes directory in the ColdFusion administrator. The administrator is where you change all server settings, just like what the php.ini file does, except it's a nice web based interface. The only thing is, you'll need to know the administrator password. To access the administrator, it's http://www.yourhosthere.com/CFIDE/administrator (Just obviously replace www.yourhosthere.com with your host).

Under "Server Settings" -> "Mappings", you'll be able to add a logical path, such as '/includes', and map it directly to a system directory, such as 'C:\inetpub\wwwroot\yoursite\someSubDir\includes' (or wherever your directory is).

Then, you'll be able to access this directory just like if it were in the web root, with
Code:
<cfinclude template="/includes/includedFile.cfm">
ColdFusion will find the mapping, and find your file.


2) You can use the variable method, like you wanted to do originally. This is obviously as simple as just creating a variable for the path to your includes file.

Code:
<!--- Set a variable to point to the includes directory --->
<cfset includesDirectory = "/subDir/myCFsite/includes">

...

<!--- Include a file from the includes directory --->
<cfinclude template="#includesDirectory#/myInclude.cfm">
If you want to only set this variable once, and in one place (so it's easy to maintain), you can put it in an Application.cfm file. Application.cfm is a special file that gets automatically included at the beginning of every request to a cfm page. If you're working on a pre-existing app, there is probably one either in the directory that you are working in, or in a parent directory. ColdFusion looks up the directory tree until it finds one to include for a request.

So you could set the variable in that Application.cfm file, and it will be available to all pages where the Application.cfm file lives, and its sub directories. Then, when you want to change the includes path, you'd only have to change it in one place.

One thing though, your app might use the newer Application.cfc file instead of an Application.cfm file. That is the more object oriented approach (CFC's are ColdFusion's classes). If so, I'll walk you through setting a request variable in that, but most apps have Application.cfm files.

---------------------------

Ok, with your changing of the title tag in your header file, you're basically going to have to use a variable in the header code, and set that variable before you include the file.

yourPage.cfm
Code:
<cfset pageTitle = "My Title">
<cfinclude template="/includes/header.cfm">
header.cfm:
Code:
<html>
<head>
  <cfif NOT isDefined( 'pageTitle' )>
    <cfset pageTitle = "Default Title">
  </cfif>

  <title><cfoutput>#pageTitle#</cfoutput></title>
</head>

<body>
...
In the example, I provided a way to give a default title if the pageTitle variable is undefined when the header template is included. The cfoutput tags are just for outputting ColdFusion variables onto a page.
Gjslick is offline   Reply With Quote
Old 11-08-2009, 07:41 PM   PM User | #5
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
this is helpful thanks. so with the application.cfm or cfc file is that something I would have control of? the problem i'm having is that i don't have any real access to the servers. i just know they run CF and the IT guys aren't being very accomodating so i'll have to pass off my files to them when I'm done. I've downloaded and installed the developers edition on my mac so I can test stuff out but anything that will involve accessing administrative panels I'm not going to have access to.
wyclef is offline   Reply With Quote
Old 11-08-2009, 08:35 PM   PM User | #6
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Ok, I see. Then I guess you'll have to use the global variable method of setting your includes path.

But yes, all you have to do is create a file named Application.cfm in your directory, and ColdFusion will automatically find it and include it at the beginning of every request to the cfm files in that directory. There is also another 'special' file that will automatically get included at the end of every request if needed, which you just name: OnRequestEnd.cfm

Not having server access is a bummer though. You might run into a problem in that they probably already have an Application.cfm file in the web root, with the code needed to define application and session management. Ideally, you would put the cfset for your global variable in that file.

The problem is, if the server finds an Application.cfm file in the directory of a requested template, it will stop looking up the directory tree for one, and therefore not include their Application.cfm file. However, I would just go with what you're doing, and then when you give them your files, just tell them that they'll have to copy whatever is in your Application.cfm file into theirs, and then remove your file.

Real quick though, you might want to ask them if they use an Application.cfm file or an Application.cfc file. If they use the cfc version, you might have to put your variable into the request scope, instead of the global (i.e. page variables) scope. It's kind of the same thing, but would just be declared as request.includesDirectory instead.

Ex:
Code:
<cfset request.includesDirectory = "/dir/dir2/includes">

<cfinclude template="#request.includesDirectory#/myInclude.cfm">
Greg
Gjslick is offline   Reply With Quote
Old 11-09-2009, 07:41 PM   PM User | #7
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
whats with this site? http://www.communitymx.com/content/a....cfm?cid=8316B
it says not to use the body or head tag in an included file?
wyclef is offline   Reply With Quote
Old 11-09-2009, 08:25 PM   PM User | #8
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Hmm, I think he's talking about using an include for each of the "pieces" of his page. He's saying not to put header code in those includes, because he already has it all in his main page.cfm (in his attached files). I don't know how he was planning on implementing navigation, but it seems that he would duplicate his <html>, <head>, and <body> tags for each unique page, and just include the common pieces in (like his display header, site nav, and display footer).

Just a matter of design I guess. His design does seem to be more flexible though than the simple "header code include," in the fact that each page can have a unique title, and include whichever scripts and style sheets that they need. You just lose the maintenance capability of being able to quickly change the doctype for all of your pages at once, which really isn't that much of a big deal.

I personally use a popular framework called Fusebox to handle this kind of code sharing (which is actually both a ColdFusion and a PHP framework. www.fusebox.org), but I'm not sure you'd want to get involved with that at this point, as there is a bit of a learning curve (and you already have one for ColdFusion).

If that is the kind of site that you are developing though, where you'd have common pieces shared between all pages, then I'd personally go with what he is suggesting.

-Greg
Gjslick is offline   Reply With Quote
Old 11-09-2009, 08:53 PM   PM User | #9
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
i''ll check that out. i was also looking at mura. not really sure about frameworks at this point though. ok thats good about being able to include main tags in an include file... i'd rather lay mine out a bit differently where i have a couple big includes with variables in them.
wyclef is offline   Reply With Quote
Old 11-09-2009, 10:16 PM   PM User | #10
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Yeah, whichever design works best for you. As long as all of the html formatting for the page comes together correctly in the end, the browser won't care.

Also, ColdFusion basically just ignores and doesn't process anything that is not a cf tag (just like php ignores anything that is not between <? and ?> tags), so it really doesn't matter which html tags or text that you put in each file. You can always do View -> Page Source in your browser when your page loads, to check that your final html output is coming together correctly.

-Greg
Gjslick is offline   Reply With Quote
Old 11-09-2009, 10:58 PM   PM User | #11
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
hey, if i set a variable is it fine to use it twice?
wyclef is offline   Reply With Quote
Old 11-09-2009, 11:04 PM   PM User | #12
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Yeah, of course.
Gjslick is offline   Reply With Quote
Old 11-24-2009, 04:37 PM   PM User | #13
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
Hey Gjslick,

Do you know where someone can go to find freelance CF help? I'm working on a project with a developer who might fall through and am trying to figure out a backup.
wyclef is offline   Reply With Quote
Old 11-24-2009, 05:13 PM   PM User | #14
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Hmm, nah, nothing that I know of personally. But a quick search of google seems to return quite a few results.

How big of a project is this btw?
Gjslick is offline   Reply With Quote
Old 12-03-2009, 07:39 PM   PM User | #15
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
hey, so is it fine to use about 8 cfincludes to make up a template?? or is that too many?

Last edited by wyclef; 12-03-2009 at 07:44 PM..
wyclef is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:41 PM.


Advertisement
Log in to turn off these ads.