title: Associating child tag data with grandparent tag using CFC-based custom tags
body: <p>The full repro case for this question is in my <a href="https://github.com/daccfml/scratch/tree/master/blogExamples/cfml/customtags/nested/3" rel="nofollow">GitHub repository</a>. I'll only reproduce the necessary bits here.</p>
  
  <p>Let's say I have this usage of some custom tags:</p>
  
  <pre><code>&lt;!--- testCfcTags.cfm ---&gt;
  &lt;cfimport taglib="cfcBasedTags" prefix="t"&gt;
  
  Text before tags&lt;br&gt;
  &lt;t:grandparent gp:attr="set in grandparent"&gt;
      Text in grandparent, before parent&lt;br&gt;
      &lt;t:parent p:attr="set in parent"&gt;
          Text in parent, before child&lt;br&gt;
          &lt;t:child c:attr="set in child"&gt;
              Text in child&lt;br&gt;
          &lt;/t:child&gt;
          Text in parent, after child&lt;br&gt;
      &lt;/t:parent&gt;
      Text in grandparent, after parent&lt;br&gt;
  &lt;/t:grandparent&gt;
  Text after tags&lt;br&gt;
  </code></pre>
  
  <p>If I was using CFM-based custom tags, and I was to want to associate data from within my implementation of the <code>child</code> tag with the <code>grandparent</code> tag, I would simply to this:</p>
  
  <pre><code>&lt;!--- child.cfm ---&gt;
  &lt;cfif thistag.executionMode eq "end"&gt;
      &lt;cfassociate basetag="cf_grandparent" datacollection="childAttributesForGrandparent"&gt;&lt;!--- this line ---&gt;
      &lt;cfassociate basetag="cf_parent" datacollection="childAttributesForParent"&gt;
  &lt;/cfif&gt;
  </code></pre>
  
  <p>Note I can associate directly to the grandparent tag.</p>
  
  <p>I cannot work out how to do this <em>cleanly</em> with Lucee's CFC-based custom tags.</p>
  
  <p>This is the best I can come up with:</p>
  
  <pre><code>// Child.cfc
  component {
  
      function init(hasEndTag, parent){
          this.parent = arguments.parent;
      }
  
      function onEndTag(attributes, caller, generatedContent){
          writeOutput(generatedContent);
          this.parent.childattributesForParent = attributes;
          this.parent.parent.childattributesForGrandparent = attributes;
          return false;
      }
  
  }
  </code></pre>
  
  <p>And in Parent.cfc I have this:</p>
  
  <pre><code>// Parent.cfc
  component {
  
      function init(hasEndTag, parent){
          this.parent = arguments.parent;
      }
  
      function onEndTag(attributes, caller, generatedContent){
          writeOutput(generatedContent);
          this.parent.parentattributesForGrandparent = attributes;
          writeDump(var=this.childAttributesForParent, label="Parent childAttributesForParent");
          return false;
      }
  
  }
  </code></pre>
  
  <p>That cumulative (mis-)usage of the <code>this</code> scope of Parent and Grandparent means from Child I can bung stuff straight into the Grandparent via <code>this.parent.parent</code>.</p>
  
  <p>However that's all a bit "<a href="http://en.wikipedia.org/wiki/W._Heath_Robinson" rel="nofollow">Heath Robinson</a>". Given the rest of Lucee's CFC-based custom tag implementation is pretty slick, I am sure I'm just missing something. I really don't think I ought to have to burrow through the Parent to get to the Grandparent. Also it means that the code would need to differ for situations in which the Child is directly within the Grandparent. What I really need is for some tag-hierarchy to be passed between CFCs, not simply the parent.</p>
  
  <p>I've googled about, but most of what's out there is written by me (which is in turn based on the blog articles originally written for Railo's implementation of this - which is what the Lucee implementation is based on).</p>
  
  <p>Docs I've already read, which are no help:</p>
  
  <ul>
  <li><a href="http://blog.adamcameron.me/2014/08/railo-cfc-based-custom-tags.html" rel="nofollow">Railo: CFC-based custom tags</a></li>
  <li><a href="http://blog.getrailo.com/post.cfm/cfc-based-custom-tags-by-example-part-1" rel="nofollow">CFC-based Custom Tags by Example - Part 1</a></li>
  <li><a href="http://blog.getrailo.com/post.cfm/cfc-based-custom-tags-by-example-part-2" rel="nofollow">CFC-based Custom Tags by Example - Part 2</a></li>
  <li><a href="http://blog.getrailo.com/post.cfm/cfc-based-custom-tags-by-example-part-3" rel="nofollow">CFC-based Custom Tags by Example - Part 3</a></li>
  </ul>