6 Replies Latest reply on Jul 21, 2006 4:40 PM by twkhatadin

    Nested Custom Tags


      I have a custom tag that I've written that has some attributes. I want to nest that tag inside of itself, and access the attibutes of the parent tag. However, when I try to access the parent tag's data from the child all I get is the child tag's data! If there are two of the same custom tags in the context stack, is it possible to access one from the other? Thanks for your help.

        • 1. Re: Nested Custom Tags
          Dan Bracuk Level 5
          You want a custom tag to call itself? Why not use a loop instead?

          Or, do you want to call another custom tag from a custom tag. In that case you send the attributes the same way you would from a normal template.
          • 2. Re: Nested Custom Tags
            Level 7
            You could use the caller scope:

            But as the nots there suggest, it would be generqally be considered better
            practice to pass-in as attributes, any external values you wish to use in
            the custom tag.

            • 3. Re: Nested Custom Tags
              You might also want to take a look at the documentation for parent/child data exchange:

              http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm ?href=00001083.htm&single=true
              • 4. Re: Nested Custom Tags
                twkhatadin Level 1
                I am basically building a set of custom conditional tags. This is for a situation where <cfif> just will not work. I want to be able to nest them like the regular <cfif> tags. Each nested <cfif> adds it's structure into an attribute of it's parent tag. I have everything working; I have else if and else functionality, I can nest if tags in else if or else tags, and I can traverse and parse the entire set of tags and get the result I was expecting. The one thing I can't do is nest an if tag inside of another if tag, because the child tag can't seem to see the parent if they are the same tag. I use GetBaseTagData() to access the attributes of the parent tag, and like I said it works fine with an if tag nested in a if else or else tag. I can't use the CALLER scope, as that references the page that called the first custom tag, no matter how deeply nested I am. I'm so close to being finished, there has to be a way to do this. Thanks
                • 5. Re: Nested Custom Tags
                  Level 7
                  > I can't use the
                  > CALLER scope, as that references the page that called the first custom tag, no
                  > matter how deeply nested I am.

                  I think you should test the advice, before you make assertions like this.

                  The CALLER scope refers to the variables scope of the template that called
                  the currently executing custom tag. If your calling stack is like this:


                  Then the situation is this:
                  1) In index.cfm: no caller scope.
                  2) In customTagA.cfm: caller scope references index.cfm's variables scope.
                  3) custoTagB.cfm: caller scope references customTagA.cfm's variables scope
                  (NOT index.cfm's one).

                  Similarly, if your calling stack is like this:

                  customTag.cfm (*)

                  Then the caller scope in each customTag.cfm instance refers to the
                  variables scope of the file above it. The only caller scope that
                  references index.cfm's variables scope is the customTag instance marked
                  with (*).

                  If I understand your requirement, this is what you want. This is why I
                  suggested it.

                  • 6. Nested Custom Tags
                    twkhatadin Level 1
                    This is the code I use to write to the parent tag's attributes:

                    <cfif ListLen(ancestorList) GT 1 AND LCase(Left(ListGetAt(ancestorList,2),9)) EQ "cf_delay-">
                    ....<cfset parentData = GetBaseTagData(ListGetAt(ancestorList,2))>
                    ....<cfset parentData.ATTRIBUTES.nestedIf[ArrayLen(parentData.ATTRIBUTES.nestedIf) + 1] = thisTag>

                    The reason I can't use the CALLER scope is because I am not calling the nested tags from within the template of the parent custom tag. My tags are nested inside the opening and closing tags of the parent custom tag on the original template, like this:


                    Every time there is an <if> it writes to the containing tag's attributes. Sorry for the confusion