views:

86

answers:

3

My client has multiple companies; different names/logos etc, but all the content on the sites are identical with the exception of said names/logos.

In a ColdFusion environment, what would be the best way for me to serve up identical content and swap out the logos/company names on the fly so I can keep everything in one spot? Is this a jQuery solution? regex? Or will ColdFusion enable me to deploy this in an efficient manner based on the url and session variables?

+1  A: 

use ANT script to copy the correct logo and replace the correct name upon deploy?

or, make use of Coldbox environment detection support, and load up a different config file depending on the URL path?

Henry
+2  A: 

"Best" is a relative term. There are a large number of ways to do this.

I would probably use a switch on cgi.host_name in the onSessionStart() section of the application.cfc file. Store the correct site name, logo file, css reference, etc. in the session, and reference as needed. This, of course, presumes you are using sessions already.

If you want a more specific answer, you'll need to provide more information about what is already going on in your site.

Ben Doom
It's `cgi.host_name` rather than `cgi.host_header` - also, if you use this value as part of your application name, you can store it in the application scope instead (no need for sessions).
Peter Boughton
Ben, I'm currently in development mode. Right now the client has separate sites and needs to make updates to each site individually. I want to amalgamate the sites so it's easier to manage from a data collection/deployment perspective. I was hoping there was something straightforward like this and Adam's response. Thank you!
Ofeargall
@peter -- if you are using two separate distributions, you can save it in the app scope. I was assuming he'd use a single distribution, with two separate site pointed to it.
Ben Doom
A single distribution (server/code base) can have multiple applications linked to it, by having a dynamic application name. Ben Nadel has a good presentation (and blog entries?) on Application.cfc which discusses this (and similar things).
Peter Boughton
I hadn't thought of that. Nice trick. I'll have to use that.
Ben Doom
+2  A: 

I would recommend something similar to what @Ben Doom suggested; though not storing in session scope. Instead, I would recommend using Application scope. There's no reason to make every user's session repeat the same information over and over.

You can get 2 different "applications" (basically just different address spaces) running from the same codebase by giving them different application names. As Ben suggests, I would base the application name on a CGI variable. Using a hash will guarantee that the value will be safe to use as an application name, but won't be as easy to switch on.

Application.cfc:

component {
    this.name = hash(cgi.server_name);
}

Not all CGI variables are safe -- some can be modified by the user (referrer, ip, etc), so if you're going to use one of those, I recommend doing something like hashing it as I've done above to make sure it's safe to use here... But if you use one of the safe values (like cgi.server_name), then you should be safe using it without hashing/etc.

In that case, it would be much easier to setup the theme of the display to switch on which application is running:

Application.cfc:

component {
    this.name = cgi.server_name;
}

index.cfm:

<cfimport prefix="custom" taglib="#expandPath('./layouts')#" />
<custom:layout theme="#application.applicationname#">
    <!--- your content here --->
</custom:layout>

layouts/layout.cfm:

<cfparam name="attributes.theme" default="www.site1.com" />
<cfif attributes.theme eq "www.site1.com">
    <!--- include content for this theme --->
<cfelse>
    <!--- include content for this theme --->
</cfif>

(Tested on Win7/IIS7)

Adam Tuttle
Adam, thank you for the code samples. I believe this might just set me on the correct path. I'm hoping I can set some variables/attributes that will go throughout the site and replace everything like hidden form elements, logos and replace company names in the text.
Ofeargall
As I mentioned in my comments to my own post, I was assuming he'd use a single code deployment, which would necessitate the use of session variables. If he's doing two separate deployments, then app scope is definitely the way to go.
Ben Doom
Ben, my example works out of the same codebase - a "single code deployment" as you're putting it. Both sites running from the same code in the same folder. I tested with multiple host-headers (faked domain names), and this worked.
Adam Tuttle
Instead of hashing, I tend to replace non alphanum chars (i.e. regex \W with _ or similar) - this makes it easier to identify if you're other software that refers to app names (e.g. BugLog error tracking).
Peter Boughton
Thank you all for your input and expertise.
Ofeargall