Skip to main content
Known Participant
June 7, 2008
Question

Evaluating expressions in a variable

  • June 7, 2008
  • 4 replies
  • 335 views
I have a basic need but can't seem to find a solution. How do you evaluate expressions in a variable?

For example: I have have a text file that contains plain text & variables. I'm calling the text file via a CFFILE action=read. When I CFOUTPUT the generated variable from CFFILE I get the text file but no variables are evaluated!

Getting this: (my name is #name#)
Need this: (my name is John)

How can I read the file and output the file with all variables evaluated? Thanks
    This topic has been closed for replies.

    4 replies

    LionelR1Author
    Known Participant
    June 7, 2008
    Thanks, I knew I was missing something simple.

    Inspiring
    June 7, 2008
    > I'm familiar with CF processing (I'm CFMX 7 certified )

    Hmmm.


    > however you
    > misunderstood my question, sorry if I was'nt clear.

    Well I understood *what you said*, but...


    > Let me put it this way, how do I do this:
    > <CFOUTPUT>
    > <CFINCLUDE TEMPLATE="text.txt">
    > </CFOUTPUT>
    > text.txt (includes the following text: my name is #name#)

    ... this is different from what you said you were doing.

    CF files are executed as discrete units. When you <cfinclude> something,
    it is not copy and pasting the text within the file into the body of the
    calling file (which is what one might reasonably expect is happening, given
    how "include" constructs work in some other languages such as C).

    So the <cfoutput> tags in one file have effect only on the text within that
    very file (*literally* the exact text in the file, not what might be
    inferred as being "within" it, via some CF construct such as <cfinclude>);
    it has no effect on the text in your included file.

    You need the outputs in your text file.

    --
    Adam
    LionelR1Author
    Known Participant
    June 7, 2008
    I'm familiar with CF processing (I'm CFMX 7 certified ) however you misunderstood my question, sorry if I was'nt clear.

    Let me put it this way, how do I do this:
    <CFOUTPUT>
    <CFINCLUDE TEMPLATE="text.txt">
    </CFOUTPUT>
    text.txt (includes the following text: my name is #name#)

    The result from above is: " my name is #name# "
    but I want: " my name is john "
    Inspiring
    June 7, 2008
    > For example: I have have a text file that contains plain text & variables. I'm
    > calling the text file via a CFFILE action=read. When I CFOUTPUT the generated
    > variable from CFFILE I get the text file but no variables are evaluated!

    Why do you find it surprising that OUTPUTing the contents of the file
    doesn't execute any CFML code embedded within the file?


    > How can I read the file and output the file with all variables evaluated?

    To execute code, you need to tell the CF server to do so.

    How does one tell the CF server to execute code in a file?

    There's a number of ways:
    - browse to the file's URL. If it's got a CFM/CFC extension, the web
    server will pass the request to the CF server for execution.
    - Use CFHTTP to get the CF server itself to "browse" to the URL at which
    the file is (this still goes via the web server, so the same
    file-extenstion rules apply as per above).
    - use <cfinclude> / <cfmodule> / etc to include the file as part of the
    processing of some other template.
    - numerous other ways, less relevant to your situation.

    I'm being slightly obtuse in answering your question to encourage you to
    consider how CF processing works, in relation to files.

    --
    Adam