• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Coldfusion 9 Custom Tag -- Need help making my first one.

Greetings!  I'm really confused with the Adobe documentation on custom tags. I'm hoping someone can help me.

I have some code I use that determines if someone has permission to view a "section".  

<cfset findValue = session.dnet.permissions.indexOf('1')>
<cfif findValue GTE 0>
<cfoutput>
some code
</cfoutput>
</cfif>

I would like to do something like this... which would save a lot of code.

<cfsomething section=1>
some code
</cfsomething>

Could anyone help me with this?

0
gr1z
Asked:
gr1z
  • 2
3 Solutions
 
gdemariaCommented:
actually, it wouldn't really save any code as you could just write it like this...

<cfif find(session.dnet.permissions,"1")>
  Some Code...
</cfif>

Using a custom tag would be a tad slower because it would have to open the file and run more code, but nothing to worry about.   The benefit of the custom tag would be centralized processing, perhaps some day the code would have to change, you have it all in one place.   The custom tag would look something like this...


<cfif not thistag.HasEndTag>
	<cfset thistag.generatedcontent="">
	You must have an end Tag
	<cfexit>
</cfif>
<cfparam name="attributes.section" default="">
<cfif thistag.executionmode is "end">
    <cfif len(trim(attributes.section)) eq 0>
       Section is a required paramter
       <cfexit>
    </cfif>
    #thistag.generatedcontent#
</cfif>

Open in new window

0
 
SidFishesCommented:
i'd also suggest looking at using cfc's which also manages code centrally.

What to use depends on what you are using them for:

Custom tags are best suited for handling UI display stuff. (presentation)
CFC's are for working with data and logic (buisness logic)

I've personally gone completely away from custom tags and would handle your situation in a cfc by evaluating the permissions and returning a boolean to the calling code. But that's just personal preference.
0
 
gdemariaCommented:

 agreed sid,  to illustrate, you can create a function (even if not in a cfc) called hasPermission()

 Then it's a very simple cfif statement...


<cfif hasPermission("1")>
   .... some code ....
</cfif>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now