Skip to content

#cfunites Notes – “Advanced Custom Tags”

What is a custom tags?

  • CF custom tags are user created tags to extend the tag set
  • written in CF
  • executed on CF server
  • used along side standards tags
  • locally available

Why use them?

  • code reuse
  • encapsulation
  • abstraction
  • simplification
  • customized control flow
  • packaging

What about CFC?

  • yes everything you can do everything in CFCs but sometimes cust tags can sometimes offer a more natural feeling

Basics

  • stored anywhere the server has access to
  • invoking: cf_, cfModule, cfImport
  • execution: open, close, self-close
  • scopes: attributes, thisTag, caller, variables
  • passing data to/from:

Gathering and consuming data

  • using custom tags as functional facades
  • implicit execution

Leverage Relative Addressing of Template

  • use custom tag as a proxy to CFC creation
  • CFC names as relative to tag proxy location

Can be recursive!

Examples

regEx Loop  (cf_reLoop) – loop tag to easily access Java’s regular expression matching functionality (faster/more robust than CF)

template mailer (cf_mail) – tag to encapsulate passed in data into a template and then mailed

navigation/navigationItem – set of tags to create a navigation with as many items as needed. handles hover functionality. decouples where a link is going from how it works to get there makes it easier to change either property later.

  • cfAssociate is used to pass attributes from parent into the child
  • cfExit method=”exittag” is used at the bottom to only let the tag be called once regardless of if it is a self-closed ta

switchLoop – works like cfSwitch but allows for “resetting” of expression. allows for two different cases to be hit.

randomSwitch – works like cfSwitch but a random case is selected.

renderXml – recursive tag to loop through an XML document.

Resources

http://www.bennadel.com/

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*