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

Posted on 2011-04-29
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>
some code

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

<cfsomething section=1>
some code

Could anyone help me with this?

Question by:gr1z
    LVL 39

    Accepted Solution

    actually, it wouldn't really save any code as you could just write it like this...

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

    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
    <cfparam name="attributes.section" default="">
    <cfif thistag.executionmode is "end">
        <cfif len(trim(attributes.section)) eq 0>
           Section is a required paramter

    Open in new window

    LVL 36

    Assisted Solution

    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.
    LVL 39

    Assisted Solution


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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
    Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math ( While this method is not o…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now