[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-04-29
3
Medium Priority
?
338 Views
Last Modified: 2012-06-27
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
Comment
Question by:gr1z
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 1332 total points
ID: 35492532
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
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 668 total points
ID: 35492616
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
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 1332 total points
ID: 35492700

 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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 10 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question