Search code examples
databasecoldfusionevaluate

ColdFusion: Storing tags inside database outputs as string


I am creating a CMS system which has a rewrite rule to use only one page. From that page I am then pulling the content from a database to populate each page based on its url. This all works fine, however, on some pages I also want to use ColdFusion tags that are stored in the database tables i.e. <cfif> etc.

When the page renders it outputs the tags as html instead of ColdFusion running the tag. I found a way to get it working by using Evaluate() around the content. However, reading up on this apparently has massive performance issues.

I was therefore wondering what other options I could use to get this working.


Solution

  • You should be able to write the data to a file and then use <cfinclude> to include it on your page

    Untested, but something like this should work.

    <cfset NewFileName = CreateUUID()&'.cfm'>
    <cffile action="write" file="YourPath\#NewFileName#" output="#DatabaseInfo#">
    <cfinclude template="#NewFileName#">
    <cffile action="delete" file="YourPath\#NewFileName#">