Skip to main content
April 24, 2012
Question

Scripting Questions

  • April 24, 2012
  • 2 replies
  • 496 views

1.) In queries with conditionals (if-statements or dynamic variables), how would I implement this in the scripting syntax?

Example:

SELECT *

FROM ExampleTable

WHERE

<cfif arguments.Example eq "Example">

     IN(<cfqueryparam value="arguments.myExample" list="yes" />)

<cfelse>

     '#arguments.myExample#'

</cfif>

2.) In scripting, what happens if you include templates not in <cfscript> such as HTML or tag based CFML? I tried using include a couple times and it wouldn't work, and I'm assuming the reason is because what I was including was HTML and/or tag based.

    This topic has been closed for replies.

    2 replies

    Inspiring
    April 25, 2012

    Regarding:  "In scripting, what happens if you include templates not in <cfscript> such as HTML or tag based CFML?"

    You get an ugly grey box on your monitor with an informative message inside. 

    Inspiring
    April 24, 2012

    1.) In queries with conditionals (if-statements or dynamic variables), how would I implement this in the scripting syntax?

    One builds up the string first, eg:

    sql = "

    SELECT *

    FROM ExampleTable

    WHERE

    ";

    if (arguments.Example eq "Example"){

         sql &= "IN(?)";

    }else{

         sql &= "'#arguments.myExample#'";

    }

    Then passes the string to the call to Query.cfc.

    Parameters are done slightly differently than in a <cfquery> tag in that one only needs a place holder in the SQL string, and then set the parameter details separately with addParam().

    It's all documented here:

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0693d5dae123bcd28f6d-7ffb.html

    2.) In scripting, what happens if you include templates not in <cfscript> such as HTML or tag based CFML? I tried using include a couple times and it wouldn't work, and I'm assuming the reason is because what I was including was HTML and/or tag based.

    The included files are compiled separately, so it doesn't matter what code is within them compared to the including template.

    As to why you had problems, it's impossible to say given the only info you offer is "wouldn't work".  You don't tell us in what way it "wouldn't work".

    --

    Adam