The show() Method

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


    item = { name = 'CoreConX', version = '0.0.7', model = 'Town & Country' };
    writeOutput( item, 'name') ); // 'CoreConX'
    writeOutput( item, 'fakeName') ); // ''
    writeOutput( item, 'version', 'Version: ', '!') ); // 'Version: 0.0.7!'
    writeOutput( item, 'model') ); // 'Town &amp; Country'
    writeOutput( target = item, property = 'model', makeHTMLSafe = false ) ); // 'Town & Country'
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.