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

Custom IF tag

New Here ,
Jun 22, 2006 Jun 22, 2006

Copy link to clipboard

Copied

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"
rowSpan="2"/>
<cf_report-display-data-value columnNameList="exp_cnt">
<a href="...">{{exp_cnt}}</a>
</cf_report-display-data-value>
</cf_report-display>

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
</cf_delay-else-if>
<cf_delay-else>
Option 3
</cf_delay-else>
</cf_delay-if>

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 >
...
<cfelseif>
...
<cfelse>
...
</cfif>

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

Thanks for the help

Tim
TOPICS
Advanced techniques

Views

337

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 ,
Jun 22, 2006 Jun 22, 2006

Copy link to clipboard

Copied

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

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 ,
Jun 23, 2006 Jun 23, 2006

Copy link to clipboard

Copied

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!!

Thanks
Tim

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 ,
Jun 26, 2006 Jun 26, 2006

Copy link to clipboard

Copied

LATEST
Anyone?

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
LEGEND ,
Jun 23, 2006 Jun 23, 2006

Copy link to clipboard

Copied

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

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 ,
Jun 23, 2006 Jun 23, 2006

Copy link to clipboard

Copied

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!

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