5 Replies Latest reply on Jun 26, 2006 1:46 PM by twkhatadin

    Custom IF tag

    twkhatadin Level 1
      Hello. I have a custom tag that I've written for report display that goes through a object with a query and outputs it in a table. There is a sub-tag that allows you to specify special output for a specific column. Here is an example:

      <cf_report-display reportObject="#REQUEST.g_reportData#">
      <cf_report-display-header-value tagMode="default" useColName="true"
      <cf_report-display-data-value columnNameList="exp_cnt">
      <a href="...">{{exp_cnt}}</a>

      This works wonderfully. The calling page does not look at the query, so any calls to fields in the query can only occur inside the tag, so I wrap these calls with {{ }} and use a regex to parse out the code, and then use evaluate to run it. Works great.

      The problem I'm having is if I want to do conditional logic on a query field, such as:

      <cfif exp_cnt GT 100>

      I can't write a <cfif> because the calling page can't process the fields and the <cfif> gets processed before it's passed to the custom tag. I tried coding a iif() in a string and using DE() and evaluate() in the tag, but that didn't work correctly either, the if statement would run, but the code to run in if the condition worked would not display right. Plus it made for some very hard to read code.

      So I am trying to write a custom if tag, that allows you to specify the condition, and then in the tag body put the code to run if the condition passes. I would like to have the same features as the <cfif>, <cfelseif>, and <cfelse> tags:

      <cf_delay-if condition="exp_cnt LT 100">
      Option 1
      <cf_delay-else-if condition="exp_cnt LT 200">
      Option 2
      Option 3

      I can get this part to work too. My problems are:
      1) I wanted to allow nested if's.
      2) If I do nested Ifs, and I have the if tag associated with my report tag, will it work? Do I have to associate the if tag with my report tag to pass data between them?
      3) I also wanted to see if I could write this with the same syntax as <cfif>:

      <cfif >

      This is just a wish, not a requirement, but it would be nice.

      Thanks for the help

        • 1. Re: Custom IF tag
          twkhatadin Level 1
          I also wanted to know if you can modify a tag's parent tag data with GetBaseTagData(), or is this a read only data access method?


          • 2. Re: Custom IF tag
            Level 7
            I believe so, the proper way to modify the parent tags data is with the
            caller scope.

            caller.foobar will reference variables.foobar in the parent tag.

            twkhatadin wrote:
            > I also wanted to know if you can modify a tag's parent tag data with GetBaseTagData(), or is this a read only data access method?
            > Thanks
            > Tim
            • 3. Re: Custom IF tag
              twkhatadin Level 1
              I'm trying to use the caller scope, but it doesn't want to work. I have an attribute variable in my <cf_delay-if> that I try to write to if I'm in a nested tag:

              <cfset CALLER.ATTRIBUTES.nestedIf = thisTag>

              I've tried it with and without the ATTRIBUTES. but in both cases all I get at the end is an empty stucture. However, if I do a dump of CALLER.ATTRIBUTES.nestedIf and a <cfabort> right after making this call, I get what I want to see. I have no idea what's wrong!
              • 4. Custom IF tag
                twkhatadin Level 1
                OK, I've figured out most of my problems. I've found a way to do the nested IFs, you use the GetBaseTagData to modify a parent tag's data as using CALLER refers to the template that called the first custom tag, no matter how deeply you're nested. I have one last major problem. If I have a <cf_delay-if> tag nested in a <cf_delay-else>, everything works fine. But if I try to nest <cf_delay-if> inside another <cf_delay-if>, when I try to access the parent tag data all I get is the current tag! If there are two of the same custom tags in the context stack, is it possible to access one from the other? Help!!

                • 5. Re: Custom IF tag
                  twkhatadin Level 1