Sounds like you would like to modify your response after it has been built, but before it is returned to the web server.
There are several places you can do this.
1) With an Application.CFC you can do it in the OnReqeust() function. If you build on OnReqeust() function, this code can be run after the reqeust has been built, but before it is returned to the web server. Be aware that using this function can have a profound affect on web service and ajax reqeusts, so plan accordingly.
2) You could build similar functionality into your own code. Instead of building your response straight into ColdFusion's response out buffer, build it into a variable that you can manipulate before "outputing" it into the response out buffer.
3) You can do similar functionality by tapping into the underlining java request/response object to intercept the resposne before it is sent to the web server.
You could rework your logic flow so that the system knows what header needs to be used at the time the header is being generatated so as to avoid the above intercepts and convolutions.,
You could modify my custom tag to add a line for the META description. Currently, it does exactly what you are asking for but only for the TITLE tag.
Beautiful in it's simplicity! Thank you! Works great for me for the title so far. Now I have a question about the meta description. What is the correct syntax to use in the ReReplaceNoCase function? There are several meta tags so I need to be sure to get only the description tag. But if I am to include enough string for it to find and remove only the description tag, there is a quotation mark that will mess up the function call - see the red quotation mark below. Can I escape that somehow?
<meta name="description" content="Lot's of great stuff">
ReReplaceNoCase(pageContent,"<meta name="description.*>", "", "ALL")
You can just change the quotes around that argument to single quotes. Like this...
ReReplaceNoCase(pageContent,'<meta name="description.*>', "", "ALL")
ReReplaceNoCase(pageContent,'<meta name="description.*?>', "", "ALL")
I think I tried that in one of my iterations, but if it doesn't work, this does. I figured it out just a bit ago and hadn't gotten it posted yet.
ReReplaceNoCase(pageContent,'<meta name="description(.|\n)*?>', "", "One")
So for the custom tag for any meta tag, I created this which works like a charm...
<cfif thistag.executionmode IS "start">
<cfparam name="attributes.MetaName" default="" type="string">
<cfparam name="attributes.newContent" default="" type="string">
pageContent = getPageContext().getOut().getString();
pageContent = ReReplaceNoCase(pageContent,'<meta name="#attributes.MetaName#(.|\n)*?>', "", "One");
writeOutput( pageContent );
<cfhtmlhead text = "<meta name=#Chr(34)##attributes.MetaName##Chr(34)# content=#Chr(34) & htmleditformat(attributes.newContent) & Chr(34)#>">
Call it using this...
<cf_UpdateMetaTagContent MetaName="description" newContent="#variables.NewDescription#" />
Thank you for your assistance, tSpark. This is perfect.