Skip to content
Miles Rausch edited this page Feb 5, 2015 · 1 revision

To make outputting properties in structs easier, we added the show() method. This method allows us to format the display of a property in a struct by wrapping strings around it. The resulting string will only be returned if the property exists.

We find this technique to be very helpful when outputting data that may have many optional properties. By using a series of show() methods, we can eliminate a lot of boilerplate code that would otherwise check if the property has been defined within the structure.

The function also performs very simple formatting on booleans to produce "yes/no" formatted output instead of "true" or "false".

Allows five arguments:

  • required struct target -- the structure you're targeting
  • required string property -- the property you're looking for
  • string wrapBefore = '' -- any string that should be output before your property value
  • string wrapAfter = '' -- any string that should be output after your property value
  • boolean makeHTMLSafe = true -- control whether the property should be output in HTMLEditFormat

Example:

<cfscript>
    item = { name = 'CoreConX', version = '0.0.7', model = 'Town & Country' };
    writeOutput( coreconx.show( item, 'name') ); // 'CoreConX'
    writeOutput( coreconx.show( item, 'fakeName') ); // ''
    writeOutput( coreconx.show( item, 'version', 'Version: ', '!') ); // 'Version: 0.0.7!'
    writeOutput( coreconx.show( item, 'model') ); // 'Town &amp; Country'
    writeOutput( coreconx.show( target = item, property = 'model', makeHTMLSafe = false ) ); // 'Town & Country'
</cfscript>
Clone this wiki locally