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.
#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.
#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.
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.
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
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.
<!--- Set a variable to point to the includes directory --->
<cfset includesDirectory = "/subDir/myCFsite/includes">
<!--- Include a file from the includes directory --->
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.
<cfset pageTitle = "My Title">
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.
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.
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.
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.
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.
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.