Customer Helpers

2 views
Skip to first unread message

Randy Johnson

unread,
Nov 25, 2009, 8:14:24 PM11/25/09
to ColdFusion on Wheels
Hello,

Does anyone have any examples of customer helpers you have made?  doesn't need to be code, just the name / brief explanation.

Thank You!

Randy


Chris Peters

unread,
Nov 25, 2009, 8:22:15 PM11/25/09
to cfwh...@googlegroups.com
Here's one used on cfwheels.org. Basically, we can link to a function's documentation information anywhere on the site by running one of these lines of code:

#functionLink("findAll")#
or
#functionLink(functionName="exists", mask="hasXXX")#

The reason for the optional mask argument is that our documentation generator doesn't pick up the dynamic association methods described in the Associations chapter.

Here's the code in views/helpers.cfm:

<cffunction name="functionLink" hint="Builds a link to a given function's documentation.">
    <cfargument name="functionName" type="string" hint="Name of function.">
    <cfargument name="mask" type="string" required="false" default="" hint="Name to display instead of the `functionName` argument. Useful for linking `addXXX()` to `updateByKey()`, for example.">
   
    <cfset var loc = {}>
   
    <cfif Len(arguments.mask) gt 0>
        <cfset loc.displayName = arguments.mask>
    <cfelse>
        <cfset loc.displayName = arguments.functionName>
    </cfif>
   
    <cfreturn linkTo(text="<code>#loc.displayName#()</code>", route="function", title=arguments.functionName)>
   
</cffunction>


--

You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.

raulriera

unread,
Nov 25, 2009, 9:37:19 PM11/25/09
to ColdFusion on Wheels
Hey Randy,

Think of helpers as pieces of code that will help you process your
views (but they should never ever, access the data model of your
application.. it is best practice to leave that stuff to the Models)
so a helper to display a link (Chris example) is a great way to use
helpers...

Another example will be a "humanize" function, where it will take a
"non human readable" string like "myUsernameIs" and turn it into "My
Username Is"

Chris Peters

unread,
Nov 25, 2009, 11:36:10 PM11/25/09
to cfwh...@googlegroups.com
A rule of thumb that I use for helpers vs. partials, by the way:
  • If the piece of code is going to produce a lot of HTML, use a partial
  • If the piece of code is going to produce text only, a complex value, and/or minimal HTML, create a helper
Hope that helps. I believe that's outlined somewhere in the reference guide too, but it never hurts to remind everyone.

Randy Johnson

unread,
Nov 25, 2009, 11:48:40 PM11/25/09
to cfwh...@googlegroups.com
It does.  Thanks guys

Randy
Reply all
Reply to author
Forward
0 new messages