Nick Van Brunt
Nick Van Brunt

Reputation: 15474

cfsavecontent + cfinclude with utf-8 charset?

I have a line of coldfusion code that includes an cfm file encoded with the utf-8 charset and saves it to a variable. The problem I am having is that there is no way to specify a charset in cfinclude and the resulting variable does not seem to be reading utf-8 correctly so any non ascii characters are rendered incorrectly.

<cfsavecontent variable="content">
  <cfinclude template="test.cfm">
</cfsavecontent>
<cfoutput>#content#</cfoutput>

If I use cffile this is not a problem because I can specify a chaset, but the file is not parsed for coldfusion variables.

<cfset path = expandPath(".") & "\test.html">
<cffile action="read" file="#path#" variable="content" charset="utf-8">
<cfoutput>#content#</cfoutput>

So my question - Is there a way to load a parsed coldfusion file into a variable while honoring a specific charset?

Upvotes: 4

Views: 2422

Answers (2)

duncan
duncan

Reputation: 31912

I think you need the cfprocessingdirective in both the included file and the master file.

Upvotes: 0

Edward M Smith
Edward M Smith

Reputation: 10627

I don't know if this will work or not, but the only thing I can think of is to put a

<cfprocessingdirective pageencoding="utf-8" />

tag at the very top of the code being included (test.cfm). This instructs CF to use a specific encoding when compiling the code.

Upvotes: 9

Related Questions