5 Replies Latest reply on Jul 28, 2006 5:21 PM by Dan Bracuk

    Custom tags with internal cfsavecontent

    jedale
      I am trying to create a custom tag to simplify the repeative code that I am now using. The problem I am facing is that to get the code to work I have to change the names of the cfsavecontent variables every time I call on the custom tag. This needs to be done because I will have to call the custom tag a few times on one page. I was wondering if anybody had some ideas on how to implement this code to work for multiple instances on one page? Any help would be great even if you tell me it can't be done.

      Thanks,
      Jeff
      .
        • 1. Re: Custom tags with internal cfsavecontent
          Dan Bracuk Level 5
          I only looked at the part of your code that is visible without horizontal scrolling, but I didn't see anything where you are passing information back to the calling page. In this specific custom tag, you want to pass back variable names. One of them is Attributes.RangeNum. The syntax to do that is:

          <cfset rslt=evaluate("caller.#attributes.RangeNum# = attributes.RangeNum")>
          • 2. Custom tags with internal cfsavecontent
            jedale Level 1
            Dan~

            Just to let you know, this is the first custom tag I have tried to do, so I don't know all the tricks. I don't understand why I would need to pass back a variable if the cfsavecontent is in the custom tag. The first part of my code where I reference #attributes.RangeNum# in the cfsavecontent is called by an onChange event for the first Datefield. The problem is that when I put this tag on a page multiple times I have duplicate cfsavecontent tags and I don't know how I can change the variable names each time. The first part of the code I posted above is an attempt to do this, but I had no luck. The second part of the code above shows you a working example of what I want to make a the custom tag to do. Is this even possibe? Should I put the cfsavecontent on the same page as the custom tag is called on and manipulate it that way?

            Any help would be awesome!!
            Thank you for your time.
            Jeff
            • 3. Re: Custom tags with internal cfsavecontent
              Dan Bracuk Level 5
              The reason you have to pass information back to the calling page is that custom tags are bits of reuseable code that are available to any cf template. These templates don't necessarily have to be written by the same person, or have the same variable names.

              The same concept is true with User Defined Functions, either inside or outside components. It's what makes the code so re-useable.
              • 4. Re: Custom tags with internal cfsavecontent
                jedale Level 1
                Thanks, I understand now. I haven't needed to return a variable yet and now after looking at the documentation it looks simple.

                The only other question that I have is changing the <cfsavecontent> tag's variable name every time the custom tag is called. What I was thinking is that I could pass the custom tag a "attributes.RangeNum" variable and this could be used to change the cfsavecontent variable name. The only problem is that I can't get it to work. Let me know if this is even possible.


                Thanks for your help
                Jeff

                • 5. Re: Custom tags with internal cfsavecontent
                  Dan Bracuk Level 5
                  It looks ok as far as sending an attribute in to the custom tag. Of course there is no code I see that sends anything back to the calling page.

                  At what point do things go awry?