• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Simplest of components won't run.

New Here ,
Jan 29, 2016 Jan 29, 2016

Copy link to clipboard

Copied

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:

cf components 2.png

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.

TOPICS
Getting started

Views

484

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 01, 2016 Feb 01, 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.

Votes

Translate

Translate
Community Expert ,
Feb 01, 2016 Feb 01, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2016 Feb 26, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2016 Feb 26, 2016

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation