0

Where in coldbox would you add a function that would be visible in your view thats global for instance, i want to create a function that replaces spaces with hyphens for a URL

public string function makeUrl(url) {
replace bit here    
    return URL;
}

where would you store this?

Rob
  • 53
  • 1
  • 2
  • 9

2 Answers2

0

You can create a view helper.

This is a page with that can contain user defined ColdFusion functions. Your view will have automatic access to it.

More details here: https://coldbox.ortusbooks.com/the-basics/layouts-and-views/views/view-helpers

However, for your specific case, you may want to consider using JavaScript instead.

user619882
  • 350
  • 3
  • 13
0

Create a viewsHelper.cfm file and add your global function.

also add your viewsHelper.cfm path in your config > coldbox.cfc file.

See link https://coldbox.ortusbooks.com/the-basics/layouts-and-views/helpers-udfs

Kishore Vaishnav
  • 510
  • 3
  • 17