Skip to main content
amy_yl
Participant
January 29, 2016
Answered

Simplest of components won't run.

  • January 29, 2016
  • 1 reply
  • 630 views

Oh my word. Years ago I did a project in ColdFusion spaghetti tags, and am now back on it and wanting to improve it. Learning about Components, so I can stash the mostly reused code properly. I'm following a simple how-to on components from Components | Learn CF in a Week. And the darn thing will not work.

I keep getting the error:

But... syntax looks fine to me, and it's a direct cut and paste from the tutorial, anyway.

Here is Greeting.cfc:

<cfcomponent>

  <cfscript>

  component {

  variables.baseGreeting = "Hello, ";

  public string function getFullName (String firstName, String lastName) {

  var fullName = arguments.firstName & " " & arguments.lastName;

  return fullName;

  }

  public string function getGreeting (String firstName, String lastName) {

  var fullName = getFullName(argumentCollection=arguments);

  var greeting = variables.baseGreeting & fullName;

  return greeting;

  }

  }

    </cfscript>

</cfcomponent>

And here is the simple call page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

<body>

<cfset Greeting = CreateObject("Component", "\CustomTags\Greeting.cfc") />

<cfset myGreeting = Greeting.getGreeting(firstName="Emily", lastName="Christiansen") />

<cfoutput>

    #myGreeting#

</cfoutput>

</body>

</html>

What the everlovin' is going on here!?

Thanks in advance for the clue. Obviously, I have a long road ahead of me.

This topic has been closed for replies.
Correct answer BKBK

amy_yl wrote:

Here is Greeting.cfc:

<cfcomponent>

  <cfscript>

component {

You are attempting to define a component within a component. That is not allowed. Use just one.

1 reply

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
February 1, 2016

amy_yl wrote:

Here is Greeting.cfc:

<cfcomponent>

  <cfscript>

component {

You are attempting to define a component within a component. That is not allowed. Use just one.

amy_yl
amy_ylAuthor
Participant
February 26, 2016

Oh, I get it. I think. Thanks! (Yes, just getting back around to this... too much stuff going on!) I'll report back with results.

amy_yl
amy_ylAuthor
Participant
February 26, 2016

Yup, simple. Makes sense now that I look at it fresh.