Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Self-Closing Custom Tags

Status
Not open for further replies.

cfnickname

Programmer
May 19, 2004
2
US
Hi all.
I'm new to this forum, and somewhat relatively new to ColdFusion.

I'd appreciate it if someone could answer the following question:

Is there any way to tell whether a custom tag is self-closing as opposed to being part of an opening/closing pair?

No one at the office seems to know.


 
i dont really understand the question, are you asking how do you know if you need ending tags? if it helps, here is MMs explanation of closing custom tags

However, you can create custom tags that have both a start and an end tag. For example, the following tag has both a start and an end tag:

<cf_date>
...
</cf_date>

ColdFusion calls the custom tag page date.cfm twice for a tag that includes an end tag: once for the start tag and once for the end tag. As part of the date.cfm page, you can determine if the call is for the start or end tag, and perform the appropriate processing.

ColdFusion will also call the custom tag page twice if you use the shorthand form of an end tag:

<cf_date/>

You can also call a custom tag using the cfmodule tag, as shown in the following example:

<cfmodule ...>
...
</cfmodule>

If you specify an end tag to cfmodule, then ColdFusion calls your custom tag as if it had both a start and an end tag.
 
No.

I mean how can you tell if the person who uses the tag wrote:

<cf_myCustomTag> ... other code here ... </cf_myCustomTag>

or whether he wrote:

<cf_myCustomTag/>

How can my code distinguish between:
(a) An opening/closing tag-pair (first case)
(b) A single self-closing tag (second case)
 

This code shows you how to check for it and only run the tag if it is valid..

Code:
<cfoutput>
  <cfif thistag.hasendtag is "False">
    ..bad syntax..
  <cfelse>
    <cfif thistag.executionmode is "end">
      The contents between the start and end of the custom tag are #thistag.generatedcontent#.. and now here they are reversed.. #reverse(thistag.generatedcontent)#...
    </cfif>
  </cfif>
</cfoutput>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
And also using just my code above you'd get the contents once, the contents backwards once, and the contents again...

So you can change:

The contents between the start and end of the custom tag are #thistag.generatedcontent#.. and now here they are reversed.. #reverse(thistag.generatedcontent)#...

to:

The contents between the start and end of the custom tag are #thistag.generatedcontent#.. and now here they are reversed.. #reverse(thistag.generatedcontent)#...
<cfset thistag.generatedcontent="">

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top