Skip to main content
April 20, 2012
Answered

how to translate tags to CFScript

  • April 20, 2012
  • 1 reply
  • 906 views

I want to use "pure" CFScript in my coding. there are many problems.

tags: <cfinclude to cfscript include

tags:

<cfswitch expression="#REQUEST.Attributes.Go[ 1 ]#">

<cfcase value="error">
  <cfinclude template="./content/error/_index.cfm"/>
</cfcase>

<cfcase value="pickup">
  <cfinclude template="./content/pickup/_index.cfm"/>
</cfcase>

<cfcase value="send">
  <cfinclude template="./content/send/_index.cfm"/>
</cfcase>

<!--- Default to home. --->
<cfdefaultcase>
  <cfinclude template="./content/home/_index.cfm"/>
</cfdefaultcase>

</cfswitch>

it works well

cfscripts:

<cffunction name="include">
  <cfargument name="template">
  <cfinclude template="#template#">
</cffunction>

<cfscript>
switch("#REQUEST.Attributes.Go[ 1 ]#")
{
  case "error": include("./content/error/_index.cfm");
  case "pickup": include("./content/pickup/_index.cfm");
  case "send": include("./content/send/_index.cfm");
  default: include("./content/home/_index.cfm");
}

not work well.

ps: code(tags) above is from Ben Nadel's eCards project.

anyone can help me ? thanks!

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    You need to read the docs:

    Using switch and case statements

    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a0e0-7fdf.html#WSB69283B9-CA98-4fdf-95C2-80665F57BC82

    Note that CASE blocks need to end with a BREAK.

    Also, when asking a question, saying something "not work well" is not much help: you need to say in what way something doesn't work, eg: it causes an error, or you see something you didn't expect, etc.  Otherwise it's a bit ambiguous.

    --

    Adam

    1 reply

    Adam Cameron.Correct answer
    Inspiring
    April 20, 2012

    You need to read the docs:

    Using switch and case statements

    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a0e0-7fdf.html#WSB69283B9-CA98-4fdf-95C2-80665F57BC82

    Note that CASE blocks need to end with a BREAK.

    Also, when asking a question, saying something "not work well" is not much help: you need to say in what way something doesn't work, eg: it causes an error, or you see something you didn't expect, etc.  Otherwise it's a bit ambiguous.

    --

    Adam

    April 20, 2012

    thanks Adam! I get it just one minute ago. I'm a newbie

    <cfscript>

    switch("#REQUEST.Attributes.Go[ 1 ]#")

    {

      case "error":

      {

        include "./content/error/_index.cfm";

        break;

      }

      case "pickup":

      {

        include "./content/pickup/_index.cfm" ;

        break;

      }

      case "send":

      {  

       include "./content/send/_index.cfm" ;

       break;

      }

      default:

      {

       include "./content/home/_index.cfm" ;

       break;

      }

    }

    </cfscript>

    that work well!